web storage - Google Script PropertiesService storing data in unreadable format -
i'm trying use propertiesservice store data each user's settings appear next time load app. i'm using these properties build , run trigger. problem when try call userproperties functions following 1 set, array shows ljava.lang.object instead of actual values. i've tried things json, no avail.
form.html
<?!= include('style'); ?> <div id="formdiv"> <form id="myform"> <table class="table table-hover"> <thead> <tr> <th scope="col"> <h3 span style="font-family:arial,helvetica,sans-serif;">select</span></th> <th scope="col"> <h3 span style="font-family:arial,helvetica,sans-serif;">label</span></th> <th scope="col"> <h3 span style="font-family:arial,helvetica,sans-serif;">drive target</span></th> </tr> </thead> <tbody> <? var label = gmailapp.getuserlabels(); (i = 0; < label.length; i++) { ?> <tr> <td style="text-align: center;"> <span style="font-family:arial,helvetica,sans-serif;"><input id="index" type="checkbox" name="index" value="<?= [i]; ?>" /></span></td> <td> <span style="font-family:arial,helvetica,sans-serif;"><input id="label" type="text" style="border:none" size="60" name="label" value="<?= label[i].getname(); ?>" readonly /></span></td> <td> <span style="font-family:arial,helvetica,sans-serif;">gmail backup/<input id="target" type="text" size="60" maxlength="128" name="target" value="<?= label[i].getname(); ?>" /></span></td> </tr> <? } ?> </tbody> </table> <p><input type="submit" value="test" onclick="google.script.run.setproperties(this.parentnode.parentnode)" /> <input type="submit" value="save" onclick="google.script.run.createtrigger(); google.script.run.thanks()" /> </p> </form> </div> <?!= include('javascript'); ?>
code.gs
function doget() { var form = htmlservice.createtemplatefromfile("form") .evaluate() .setsandboxmode(htmlservice.sandboxmode.iframe); return form; } function setproperties(form) { var userproperties = propertiesservice.getuserproperties(); var formproperties = userproperties.setproperty("form", form); proptest(); } function proptest() { var userproperties = propertiesservice.getuserproperties(); var filledform = userproperties.getproperty("form"); logger.log(filledform); }
execution transcript
[15-04-29 09:54:09:912 mdt] starting execution [15-04-29 09:54:09:932 mdt] propertiesservice.getuserproperties() [0 seconds] [15-04-29 09:54:10:032 mdt] (class).setproperty([form, {index=[3, 4], target=[test 01-a, test 01-a/test 01-b, test 01-a/test 01-b/test 01-c, test 01-a/test 01-b/test 01-c/test 01-d, test 01-a/test 01-b/test 01-c/test 01-d/test 01-e, test 02 - (+_!@#$%&*), test 02 - (+_!@#$%&*)/test 02 - b (+_!@#$%&*), test 02 - (+_!@#$%&*)/test 02 - b (+_!@#$%&*)/test 02 - c (+_!@#$%&*)], label=[test 01-a, test 01-a/test 01-b, test 01-a/test 01-b/test 01-c, test 01-a/test 01-b/test 01-c/test 01-d, test 01-a/test 01-b/test 01-c/test 01-d/test 01-e, test 02 - (+_!@#$%&*), test 02 - (+_!@#$%&*)/test 02 - b (+_!@#$%&*), test 02 - (+_!@#$%&*)/test 02 - b (+_!@#$%&*)/test 02 - c (+_!@#$%&*)]}]) [0.098 seconds] [15-04-29 09:54:10:032 mdt] propertiesservice.getuserproperties() [0 seconds] [15-04-29 09:54:10:065 mdt] (class).getproperty([form]) [0.031 seconds] [15-04-29 09:54:10:065 mdt] logger.log([{index=[ljava.lang.object;@6cb426d, target=[ljava.lang.object;@a760597, label=[ljava.lang.object;@4a6901de}, []]) [0 seconds] [15-04-29 09:54:10:066 mdt] execution succeeded [0.133 seconds total runtime]
when set property value has string. if saving object make sure convert json json.stringify() first. when later value parse json object @ time.
var formproperties = userproperties.setproperty("form", json.stringify(form));
my test shows values of:
[15-04-29 13:57:20:225 edt] {"index":"1","target":["test1","test2"],"label":["test1","test2"]}
Comments
Post a Comment