google apps script - uiInstance.close() has no effect -
google apps script - uiInstance.close() has no effect -
i have next code within script google spreadsheet:
var uiinstance; function displaydialog() { uiinstance = uiapp.createapplication() .setwidth(130) .setheight(130); uiinstance.add(uiinstance.createlabel("foo")); spreadsheetapp.getui().showmodaldialog(uiinstance, 'bar'); }
this dialog intended inform user script calculating , want close dialog 1 time again 1 time script has finished work. if utilize
uiinstance.close();
inside or outside function nil seems happen though; dialog remains opened until user closes it. there solution problem?
you have "return" close uiinstance, return
needed reflect alter made ui, including closing it.
try
return uiinstance.close();
edit next comment :
uiapp instances can closed handler function, thought how using (but might have been wrong).
below little code illustration :
function displaydialog() { var uiinstance = uiapp.createapplication() .setwidth(130) .setheight(130); uiinstance.add(uiinstance.createlabel("foo")); var handler = uiinstance.createserverhandler('closedialog'); uiinstance.add(uiinstance.createbutton('close',handler)); spreadsheetapp.getui().showmodaldialog(uiinstance, 'bar'); } function closedialog(){ homecoming uiapp.getactiveapplication().close(); }
there tricky workaround can "simulate" user action. uses property of widgets trigger handler function when alter value. in illustration below used checkbox start process
it close dialog when task in dostuf done.
function displaydialog() { var uiinstance = uiapp.createapplication() .setwidth(130) .setheight(130); uiinstance.add(uiinstance.createlabel("foo")); var handler = uiinstance.createserverhandler('dostuf'); var chk = uiinstance.createcheckbox().setvalue(true).setid('chk').setvisible(false); chk.addvaluechangehandler(handler); uiinstance.add(chk); chk.setvalue(false,true)// calls dostuf function (using handler) spreadsheetapp.getui().showmodaldialog(uiinstance, 'bar'); } function dostuf(){ utilities.sleep(5000);// replace useful ... homecoming uiapp.getactiveapplication().close(); }
google-apps-script
Comments
Post a Comment