8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GASのPropertiesServiceに数字を保存したと思ったら文字列になってた

Last updated at Posted at 2017-08-03

ハマってしまったのでメモです。

GoogleAppsScript で5分の壁回避のため、プロパティに数字を保存→次回実行時に取り出して+1して使いたい状況があったのだが、どうもうまくいかずにハマりました。

miss.gs
PropertiesService.getScriptProperties.setProperty("count",1);

var count = PropertiesService.getScriptProperties.getProperty("count");
Logger.log(count+1); //→1.01

デバッグしてみると、プロパティは全て文字列として保存されてしまうようです。
ということで、Number() で解決できました。

success.gs
PropertiesService.getScriptProperties.setProperty("count",1);

var count = PropertiesService.getScriptProperties.getProperty("count");
count = Number(count);
Logger.log(count+1); //→2
8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?