Why different users have the same User Properties?

213 views
Skip to first unread message

Tuan Do

unread,
Dec 2, 2021, 7:30:23 PM12/2/21
to Google Apps Script Community
I am trying to use  getUserProperties (link) to check whether users have logged in to my account. across multiple Google spreadsheets. However, I did an experiement and it seems like different users in the same field share the same getUserProperties.

My experiement: I am trying to publish my App Script as an add-on. Right now it is bound to a Google Sheets file. Under my first email account, I set User Properties to a certain value. I then share that file with another email of my and I also gave access to that email to use my unpublished add-on. I then open the same Google Sheets file under the 2nd email. When I retrieve User Properties, it shows the same User Properties  I set earlier under the 1st email.

I wonder whether this is expected behavior. I thought User Properties are unique to each user, why 2 different emails share the same User Properties ? Thanks

Jonathan Butler

unread,
Dec 2, 2021, 9:31:38 PM12/2/21
to google-apps-sc...@googlegroups.com
Do you have the code you are using? Are you using a library?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/2cab5765-bd9c-4695-b89d-1705a694fc56n%40googlegroups.com.

Tuan Do

unread,
Dec 3, 2021, 7:21:37 AM12/3/21
to Google Apps Script Community
No I am not using any library. The code is similar to the example in that link:

With my first email, I save User Property

````
var userProperties = PropertiesService.getUserProperties();
userProperties.setProperty('DISPLAY_UNITS', 'metric');

````

With my 2nd email I retrieve User Property

````
var userProperties = PropertiesService.getUserProperties();
var units = userProperties.getProperty('DISPLAY_UNITS');

Logger.log(units)
````

Jonathan Butler

unread,
Dec 3, 2021, 8:53:51 AM12/3/21
to google-apps-sc...@googlegroups.com
Is there any chance that it was left there from a previous test? How about deleting the key from one and trying again. If not, maybe you can open a ticket for it.

Alan Wells

unread,
Dec 3, 2021, 10:45:04 AM12/3/21
to Google Apps Script Community
If the code is truly running under the authority of two different users, then the second user should not have any access to other users settings. If it's a bug, then you can create a new issue in the Issue Tracker.
You can get the user email to check for what the code thinks the current user is:

function getCurrentUser_() {
  var currentUserEmail = Session.getEffectiveUser().getEmail();
  if (!currentUserEmail) {
    currentUserEmail = "Can't get current User Email";
  }
  return currentUserEmail;
}

If you create a new Issue, you need to be very specific about how to reproduce the problem. If there is any confusion or misunderstanding at Google about what the real problem is, then the problem may never get fixed. Are you sharing the file with the second Google account? Make sure to explain that. Is the second Google account actually installing the addon or not? That's important information.
Reply all
Reply to author
Forward
0 new messages