google apps script - How to store global values correctly using Properties service in GAS? -
i have problem using google apps script. have menu in spreadsheet 2 options (set password , add time record). these options raise ui service user interfaces prompt data respectively. access add time record ask before if user authenticated. use scriptproperties = propertiesservice.getscriptproperties() , setproperty('authenticated', false) save initial value of authenticated.
1- click set password, login ok , close ui.
2- click add time record , expect receive addtime record ui (because set password first) instead receive set password ui. if login again receive same ui …again , again.
is authenticated reset false every time click in menu option no matter action did before. expected behavior? or i’m doing wrong? lot help.
var scriptproperties = propertiesservice.getscriptproperties(); scriptproperties.setproperty('authenticated', 'false'); function onopen() { var ui = spreadsheetapp.getui(); ui.createmenu('proworkflow') .additem('set pasword', 'getpassword').addseparator() .additem('add time record', 'isauthenticated').addseparator() .addtoui(); } function isauthenticated() { var scriptproperties = propertiesservice.getscriptproperties(); var value = scriptproperties.getproperty('authenticated'); if(value =='false'){ getpassword(); // @ end of function set scriptproperties.setproperty('authenticated', ‘true’); } return addtimerecord(); } function getpassword(e) { … … … var scriptproperties = propertiesservice.getscriptproperties(); var value = scriptproperties.getproperty('authenticated'); value = 'true'; scriptproperties.setproperty('authenticated', value); //change de value of uthenticated return app.close(); }
"is authenticated reset false every time click in menu option no matter action did before"
so actually.
when placing line outside of function executed on each run of function line scriptproperties.setproperty('authenticated', 'false');
sets false every time.
move should be, scriptproperties
, userproperties
- definition - working global variables since stored in global script/user scope, that's designed for..
look @ wrote in getpassword function... show above not logical (see comments in code):
var value = scriptproperties.getproperty('authenticated');// value value = 'true'; // , change constant... what's point ? scriptproperties.setproperty('authenticated', value); //change de value of uthenticated
Comments
Post a Comment