else if string match loop google script (spreadsheet) -
i working on project designed checkout button automatically fill cells in shared spreadsheet. having issues logic in "else if" loop. have ui tells user when string not matched. far able create menu, prompt , matching functions spreadsheet, stuck in else if statement returns not found message.
if (button == ui.button.ok) { text = result.getresponsetext().touppercase(); for(n=0;n<data.length;++n) { // iterate row row , examine data in column if(data[n][0].tostring().match(text)==text) { data[n][13] = newdate; data[n][14] = newtime; data[n][15] = 'yes'; data[n][16] = 'yes'; //data[n][0] = data[n][0].setbackgroundcolor('red'); var result2 = ui2.prompt( 'checkout process in progess', 'please enter yout initials: (eg. mr)', ui2.buttonset.ok); var text2 = result2.getresponsetext().touppercase(); data[n][17] = text2; } logger.log(data) sh.getrange(1,1,data.length,data[0].length).setvalues(data); // write sheet }
}
this code wrote ui prompt, when use inside loop runs in every loop, not when reach end of row.
else if(data[n][0].tostring().match(text) != text) { ui.alert('room number not found; please fill in manually.'); break; }
any highly appreciated, first time coding in google apps, far it. please give me ideas.
it have been easier if had shown whole code think don't need use else if
statement, simple else
sufficient since have 1 condition on single value.
apart that, need have approach set background colors : array use has spreadsheet values, not range object anymore... i'd suggest have second array backgroundcolors , update value array.
code :
var bgcolors = sheet.getdatarange().getbackgroundcolors(); if (button == ui.button.ok){ text = result.getresponsetext().touppercase(); for(n=0;n<data.length;++n){ // iterate row row , examine data in column if(data[n][0].tostring().match(text)==text){ data[n][13] = newdate; data[n][14] = newtime; data[n][15] = 'yes'; data[n][16] = 'yes'; bgcolors[n][0] = '#ff0000';// update color var result2 = ui2.prompt( 'checkout process in progess', 'please enter yout initials: (eg. mr)', ui2.buttonset.ok); var text2 = result2.getresponsetext().touppercase(); data[n][17] = text2; }else{ ui.alert('room number not found; please fill in manually.'); break; } logger.log(data) sh.getrange(1,1,data.length,data[0].length).setvalues(data); // write sheet sh.getrange(1,1,bgcolors.length,bgcolors[0].length).setbackgroundcolors(bgcolors); // write sheet } }
Comments
Post a Comment