hey
hey

Reputation: 119

Need some clarity with GAS userProperties

I'm programming a Telegram bot with GAS. Am I right in thinking that whenever I store something using userProperties, like

userProperties.setProperty('name', 'Alex'); 

the value gets stored for this particular instance of the script AND this particular user? Does it mean that if there are 10 more or less simultaneous instances of this script by ten different users, I will later be able to retrieve each user's respective name by calling

var username = userProperties.getProperty('name');

I get the impression that sometimes there's some sort of interference happening that results in retrieving values different from those stored for this or that user. Would appreciate some clarity here.

Upvotes: 0

Views: 116

Answers (1)

ziganotschka
ziganotschka

Reputation: 26796

IMPORTANT:

UserProperties has been deprecated, use PropertiesService.getUserProperties() instead.

As you can see in the documentation

getUserProperties()

Gets a property store that only the current user can access, and only within this script.

So indeed, if the script can be accessed by several users, PropertiesService.getUserProperties() will always retrieve the properties of the specific user who runs the script, and if there will be 10 simultaneous script executions - each user executing the script will retrieve different user properties.

Upvotes: 2

Related Questions