admin管理员组文章数量:1296237
In response to google form submission I have a script triggered to do some data checking, and highlight two possible data issues in the appropriate cells of the sheet attached to the form, as well as send an email to the user submitting the form.
Everything is working fine except for highlighting the cells in the sheet with the issues. Below are the two relevant sections of code
Section 1
var responseSheet = e.source.getSheetByName('Form Responses 1');
if (respRating != recordRating){
Logger.log('shade Rating');
Logger.log(eventRow);
Logger.log(responseArr[0].indexOf('Rating'));
responseSheet.getRange(eventRow,responseArr[0].indexOf('Rating') + 1).setBackgroundRGB(177,156,217); //Highlight the problem
Logger.log('shade Rating');
Section 2
else {
Logger.log('shade Pension No');
Logger.log(eventRow);
Logger.log(responseArr[0].indexOf('Pension Card Number'));
responseSheet.getRange(eventRow,responseArr[0].indexOf('Pension Card Number') + 1).setBackgroundRGB(177,156,217); // Highlight the problem
Logger.log('shade Pension No');
}
Now from the logging it's clear both sections of code are being executed and all the fields for getRange and setBackground methods are OK.
Here are the Cloud logs
Feb 12, 2025, 8:37:31 AM Info shade Rating
Feb 12, 2025, 8:37:31 AM Info 38.0
Feb 12, 2025, 8:37:31 AM Info 8.0
Feb 12, 2025, 8:37:31 AM Info shade Rating
Feb 12, 2025, 8:37:31 AM Info shade Pension No
Feb 12, 2025, 8:37:31 AM Info 38.0
Feb 12, 2025, 8:37:31 AM Info 7.0
Feb 12, 2025, 8:37:31 AM Info shade Pension No
All I can think is that responseSheet is no longer available BUT I have later code which does highlight an entire row properly?
Any help appreciated.
I was expecting the highlighting would show in the responseSheet but it does not. I've run out of ideas on how to debug this.
In response to google form submission I have a script triggered to do some data checking, and highlight two possible data issues in the appropriate cells of the sheet attached to the form, as well as send an email to the user submitting the form.
Everything is working fine except for highlighting the cells in the sheet with the issues. Below are the two relevant sections of code
Section 1
var responseSheet = e.source.getSheetByName('Form Responses 1');
if (respRating != recordRating){
Logger.log('shade Rating');
Logger.log(eventRow);
Logger.log(responseArr[0].indexOf('Rating'));
responseSheet.getRange(eventRow,responseArr[0].indexOf('Rating') + 1).setBackgroundRGB(177,156,217); //Highlight the problem
Logger.log('shade Rating');
Section 2
else {
Logger.log('shade Pension No');
Logger.log(eventRow);
Logger.log(responseArr[0].indexOf('Pension Card Number'));
responseSheet.getRange(eventRow,responseArr[0].indexOf('Pension Card Number') + 1).setBackgroundRGB(177,156,217); // Highlight the problem
Logger.log('shade Pension No');
}
Now from the logging it's clear both sections of code are being executed and all the fields for getRange and setBackground methods are OK.
Here are the Cloud logs
Feb 12, 2025, 8:37:31 AM Info shade Rating
Feb 12, 2025, 8:37:31 AM Info 38.0
Feb 12, 2025, 8:37:31 AM Info 8.0
Feb 12, 2025, 8:37:31 AM Info shade Rating
Feb 12, 2025, 8:37:31 AM Info shade Pension No
Feb 12, 2025, 8:37:31 AM Info 38.0
Feb 12, 2025, 8:37:31 AM Info 7.0
Feb 12, 2025, 8:37:31 AM Info shade Pension No
All I can think is that responseSheet is no longer available BUT I have later code which does highlight an entire row properly?
Any help appreciated.
I was expecting the highlighting would show in the responseSheet but it does not. I've run out of ideas on how to debug this.
Share Improve this question edited Feb 12 at 8:55 Geoff Mulhall asked Feb 11 at 22:02 Geoff MulhallGeoff Mulhall 33 bronze badges 8 | Show 3 more comments1 Answer
Reset to default 0Posting the Comment as an Answer
As per the original poster, @Geoff Mulhall, watching the spreadsheet while the code ran revealed the background color flashing on and off. This helped them find the problematic line of code and realize the issue was with their own logic.
Note: Posting this as a Community Wiki so others in the community will know that the posted code itself isn't wrong, but the issue lies with its own logic.
本文标签: highlightApps Script getRangesetBackgroundRGB not firingStack Overflow
版权声明:本文标题:highlight - Apps Script getRange.setBackgroundRGB not firing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741632017a2389420.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Logger.log(JSON.stringify(e))
. You will find that eventRow is probabye.range.rowStart
– Cooper Commented Feb 11 at 22:09sheet.getRange
incorrectly. From the AppsScript docs it seems like you need to pass a string to this function with the A1 notation (e.g.E15
) rather you are passing two arguments to this function. – Matthew Lin Commented Feb 12 at 0:30