[英]Why is google apps script changing my user property to some random code every time I save it?
I am creating an editor add-on for google sheets and I'm currently stumped on why my user property ( MY_WEBHOOK
) is being changed every time I try to save it with setProperty
to this code:我正在为谷歌表格创建一个编辑器插件,我目前很难理解为什么每次我尝试使用
setProperty
将其保存到此代码时都会更改我的用户属性( MY_WEBHOOK
):
function(){var L=h(fb(arguments));if(b&32)Vd(function(){a.apply(g||this,L)});else return m(a.apply(g||this,L))}
Here is the code I am using:这是我正在使用的代码:
code.gs
: code.gs
:
function saveSettings(url) {
PropertiesService.getUserProperties().setProperty('MY_WEBHOOK', url);
SpreadsheetApp.getUi().alert("Saved")
}
function getSettings() {
return PropertiesService.getUserProperties().getProperty('MY_WEBHOOK');
}
In my html file:在我的 html 文件中:
<body onload="get()">
<form>
<label>What is the URL?</label>
<input id="webhook-url" type="url" autofocus required placeholder="Webhook Here">
<br><br>
<input type="button" value="Save" onclick="save()">
<script>
function save() {
var url = document.getElementById('webhook-url').value
google.script.run.saveSettings(url)
alert(url)
alert(google.script.run.getSettings)
google.script.host.close()
}
function get() {
var settings = google.script.run.getSettings
document.getElementById('webhook-url').value = settings;
}
</script>
</form>
</body>
I think that there are 2 modification points in your script.我认为您的脚本中有 2 个修改点。
google.script.run.getSettings
, in this case, the function of getSettings
is not run.google.script.run.getSettings
,在这种情况下, getSettings
的 function 没有运行。 Please add ()
like google.script.run.getSettings()
.()
像google.script.run.getSettings()
。 By this, the function is run.alert(google.script.run.getSettings)
and var settings = google.script.run.getSettings
, google.script.run
returns no value.alert(google.script.run.getSettings)
和var settings = google.script.run.getSettings
, google.script.run
不返回任何值。 So in this case, withSuccessHandler
is used.withSuccessHandler
。google.script.run
is run with the asynchronous process. google.script.run
与异步进程一起运行。 When above points are reflected to your script, it becomes as follows.当以上几点反映到您的脚本时,它变成如下。
Please modify your Javascript as follows.请按如下方式修改您的 Javascript。
function save() {
var url = document.getElementById('webhook-url').value
google.script.run.withSuccessHandler(() => {
google.script.run.withSuccessHandler(e => {
alert(e);
google.script.host.close();
}).getSettings();
}).saveSettings(url);
}
function get() {
google.script.run.withSuccessHandler(settings => {
document.getElementById('webhook-url').value = settings;
}).getSettings();
}
getSettings
by get()
, and when the value is inputted and click button, the value is put by saveSettings()
and the current value is retrieved by getSettings()
and alert()
is run, and then, google.script.host.close()
is run.get()
从getSettings
中获取值,当输入值并单击按钮时,通过saveSettings()
输入值,通过getSettings()
和alert()
获取当前值alert()
运行,然后google.script.host.close()
运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.