ScriptProperties & UserProperties had been deprecated

佐手、 提交于 2020-07-22 09:19:48

问题


The documentation for the PropertiesService lists both, the ScriptProperties and UserProperties as:

Deprecated. This class is deprecated and should not be used in new scripts.

... while the DocumentProperties seem to have no page in the documentation.

Q: is there any suitable replacement for these classes, in order to use them in new scripts?


回答1:


The replacement for the deprecated classes is the class Properties.

PropertiesService has three methods getDocumentProperties(), getScriptProperties(), and getUserProperties(). Perhaps once upon a time these returned objects of those deprecated classes; but now they all return an object of class Properties.

Script properties, user properties, and document properties remain available and they are non-deprecated; it's just that the classes have been unified into Properties.

var sp = PropertiesService.getScriptProperties();
sp.setProperty("foo", "bar");
var up = PropertiesService.getUserProperties();
up.setProperty("foo", "baz");
var dp = PropertiesService.getDocumentProperties();
dp.setProperty("foo", "blargh");
Logger.log([sp.getProperty("foo"), up.getProperty("foo"), dp.getProperty("foo")]);

logs [bar, baz, blargh].



来源:https://stackoverflow.com/questions/51689943/scriptproperties-userproperties-had-been-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!