问题
I need to return the row number of a Google Form submission that has been resubmited.
I followed all of the information at: Google Forms App Script : How to check if current submission is editing response or a new response, but I get this error for trigger formSubmit:
Exception: Cannot convert '15.0' to int.
So it is correctly finding the 15th row as edited and appears to be giving me a number, but i keep getting the error when i try to use that number.
I've tried to convert it using +num
, Number()
, place the row # into a cell and change the format manually, and copy it to another cell using script and formula but I still continue to get this error when formSubmit
occurs. Can you help me determine how to fix this error?
function email(e) {
var sh = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var gid = sh.getSheetId().toString();
var last = ss.getLastRow();
var valueColumnLocation;
for(k=1;k<=ss.getLastColumn();k++) {
if (sh.getRange(1,k).getValues() == "Select Worksite") {
var valueColumnLocation = k;
break;
}
};
...
if (...){...}
else{
var rowrev = e.range.getRow();
//sh.getRange("rownumberrev").setValue(rowrev);
PropertiesService.getScriptProperties().setProperty('mykey',rowrev);
if (sh.getRange(rowrev,valueColumnLocation,1,1).getValues()=="USA"){
uploadrev()
pdfFCrev()
}
else{if(sh.getRange(rowrev,valueColumnLocation,1,1).getValues()=="GLOBAL"){
uploadrev()
pdfGLrev()
}
}
}
}
Adding more detail to original post The spreadsheet that the google form populates has columns A - CZ I'm looking to find the row that was edited and then look for a value in a specific column of that row. If that value==USA, do this or if value==Global, do that.
So in this picture, row 15 was resubmitted by the user and the change was in column E. I want to use the knowledge that row 15 was edited and we earlier found the column # of "Select Worksite" which now resides in column Z and check if the value in range(15,26,1,1)==USA or Global.
Maybe there's a completely different or better way to do this that's i'm not thinking of, but when i try to use the e.range value in the sh.getRange() i get the error it cannot convert 15.0 to int.
回答1:
Looks to me like you can do the entire function with this:
function email(e) {
PropertiesService.getScriptProperties().setProperty('mykey',e.range.getRow());
if(e.namedValues["Select Worksite"]=="USA"){
uploadrev();
pdfFCrev();
}
if(e.namedValues["Select Worksite"]=="GLOBAL"){
uploadrev()
pdfGLrev()
}
}
It pays to read the documentation while your writing your code.
on FormSubmit Event Object
回答2:
35th try is the charm. I don't think i needed to but i restated variables sh & ss. Then i changed: sh.getRange(newsub,valueColumnLocation).getValue() & now it works
else{
var sh = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var newsub = e.range.getRow();
if (sh.getRange(newsub,valueColumnLocation).getValue()=="USA"){
uploadrev()
pdfFCrev()
}
else{if(sh.getRange(newsub,valueColumnLocation).getValue()=="Global"){
uploadrev()
pdfPArev()
}
}
}
来源:https://stackoverflow.com/questions/62246016/how-to-check-if-current-form-submission-is-editing-response