UserProperties in Add-on

30 views
Skip to first unread message

Jean-Luc Vanhulst

unread,
Dec 5, 2020, 9:39:51 PM12/5/20
to google-apps-sc...@googlegroups.com
I have an add-on (finally approved etc) - but I can't for the world get userproperties to be saved.

I have tried both the deprecated 
     UserProperties.setProperty(key , value );
and 
     value = UserProperties.getProperty(key);

set and the same with the PropertyServices
var userProperties = PropertiesService.getUserProperties();

It works when I run it in my script - but as soon as I use a different spreadsheet (and gmail) account with the deployed add-on I always get a 'null' value.

Any (sheets) add-on people that can share a solution? 
I need store the API key and a Trigger ID.

Martin Molloy

unread,
Dec 6, 2020, 8:55:39 AM12/6/20
to google-apps-sc...@googlegroups.com
This works for me

 var propsUser = PropertiesService.getUserProperties();

 propsUser.setProperty(key, value)
  ...
  ...
  var retrieveProp = propsUser.getProperty(key)
 


Martin Molloy
MTMOMK Limited
Add-ons: 
Form Maker; Create forms quickly and easily using a spreadsheet interface.
SheetsIE; Automate the movement of data between files of different types.
Accounts Manager; Manage User Accounts for your domain from a spreadsheet.
Classroom Manager; Mange Google Classroom classes and class lists for one teacher or the whole domain
Password Manager; Delegate management of user password resets to trusted users.
Drive Files Metadata; use a spreadsheet to view and mange metadata about your Google Drive files.
Sheets Pages Manager; Manage the pages in your Google Sheets files.


--
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/CAKTLZ51-irO%2BCSQ5m871yhGRG7KE9Gc0H1YGCTG1zEvgyGbYNg%40mail.gmail.com.

Zack Reynolds

unread,
Dec 6, 2020, 9:07:34 AM12/6/20
to google-apps-sc...@googlegroups.com
When I look at the documentation, it seems to indicate that UserProperties is getting deprecated and we should no longer use it. What does that mean in regards to storing user-specific data like API keys?

Alan Wells

unread,
Dec 6, 2020, 9:52:51 AM12/6/20
to Google Apps Script Community
Even though UserProperties is deprecated, there is a replacement for it.
Unfortunately, the documentation fails to direct people to the newer PropertiesService.

Use:
PropertiesService.getUserProperties()

to store user properties.
See:

If PropertiesService.getUserProperties() is not working correctly,
then someone at Google would need to be able to reproduce the issue
or else they will do nothing about it.
You might want to record a video of your add-on failing to get user properties for the same add-on but
in a different spreadsheet.

Jean-Luc Vanhulst

unread,
Dec 6, 2020, 12:22:35 PM12/6/20
to google-apps-sc...@googlegroups.com
That exactly what I have ( I think :) ) 
image.png
When I run that 'myself' it works fine. When I run it on the app store deployed version I get no error STORING but I get 'NULL" retrieving
image.png
I'm just at a loss...

CBMServices Web

unread,
Dec 6, 2020, 12:31:04 PM12/6/20
to google-apps-sc...@googlegroups.com
Are these users that get null value back from this, Google Workspace accounts?

If so, check the admin console for the accounts, perhaps they have not been enabled to use this service.


Jean-Luc Vanhulst

unread,
Dec 6, 2020, 12:46:57 PM12/6/20
to google-apps-sc...@googlegroups.com
I am trying this with a separate personal gmail account, using a spreadsheet that is created and owned by that account.
I'm not getting any errors or exceptions, as per the log file.

cbmserv...@gmail.com

unread,
Dec 6, 2020, 1:30:06 PM12/6/20
to google-apps-sc...@googlegroups.com

Ok Then, the only thing that I can think of is that somewhere else in your script, you are wiping out the values which cause the null value to be stored.

 

As a test, do the write then read them out right away before executing any of the rest of the functionality and see if the values have been stored correctly. If so, you will know your problem is elsewhere.

 

From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> On Behalf Of Jean-Luc Vanhulst
Sent: December 6, 2020 9:47 AM
To: google-apps-sc...@googlegroups.com
Subject: Re: [Apps-Script] UserProperties in Add-on

 

I am trying this with a separate personal gmail account, using a spreadsheet that is created and owned by that account.

I'm not getting any errors or exceptions, as per the log file.

 

 

On Sun, Dec 6, 2020 at 12:31 PM CBMServices Web <cbmserv...@gmail.com> wrote:

Are these users that get null value back from this, Google Workspace accounts?

 

If so, check the admin console for the accounts, perhaps they have not been enabled to use this service.

 

 

On Sun., Dec. 6, 2020, 9:22 a.m. Jean-Luc Vanhulst, <jlvan...@write2market.com> wrote:

That exactly what I have ( I think :) ) 

When I run that 'myself' it works fine. When I run it on the app store deployed version I get no error STORING but I get 'NULL" retrieving

image001.png
image002.png

Alan Wells

unread,
Dec 6, 2020, 1:35:30 PM12/6/20
to Google Apps Script Community
There is obviously something strange going on.
And when that happens, what you thought you could trust, you might not be able to trust anymore.
A strange problem may have a strange answer.
So let's consider the strange things that could be happening.
I'm not saying that these are true, but unless they are ruled out, maybe consider them.
If Properties Service is slow, and you save something and then immediately try to retrieve it, the value may not be there.
That's one possibility.  I'm not saying that's what's happening, and if it is, it's concerning,
but just to make sure, maybe wait 30 seconds and see if the value is there.
If it still isn't, then that can be ruled out.
The code should work, but just to make 1000% sure,
I'd create separate functions for getting and setting the property instead of one.
I know that it may sound ridiculous, but this is a strange problem,
which may require seemingly ridiculous tests just to make sure.
If, it is determined that it's not the code, then it is somehow a failure somewhere else.
If it's a bug in Properties Service, then it should be reported on the Issue Tracker.
I did a search of the Issue Tracker.
Using:

There are a couple of interesting ones:

But I don't see anything that matches your situation exactly.

Jean-Luc Vanhulst

unread,
Dec 6, 2020, 2:47:29 PM12/6/20
to google-apps-sc...@googlegroups.com
I will post as bug I think I don’t because have no other spots than that snippet I shared where PropertiesService is called

--

CBMServices Web

unread,
Dec 6, 2020, 2:51:25 PM12/6/20
to google-apps-sc...@googlegroups.com
Before you do that, try this:

Modify the if statement to this:

If( (value != null) &&  !(typeof value === "undefined") )

This way you make sure it is not being set to null via your code elsewhere.


Jean-Luc Vanhulst

unread,
Dec 6, 2020, 4:00:09 PM12/6/20
to google-apps-sc...@googlegroups.com
Happy to change that - but the Logger statement, after the setProperty()  would have caught that?
     userProperties.setProperty(key , value );
     Logger.log( "set "+key+" - "+value);   

(Ie right now I do see them in the log:)
image.png
(and no exceptions)
but retrieve will always return null

JL

Jean-Luc Vanhulst

unread,
Dec 6, 2020, 4:06:38 PM12/6/20
to google-apps-sc...@googlegroups.com
It seems that since October or so PropertiesService is more or less broken going through dozens of issues that all link back to each other.


I appreciate the new IDE coming, but this kind of stuff is pretty important for the eco-system...

CBMServices Web

unread,
Dec 6, 2020, 6:12:52 PM12/6/20
to google-apps-sc...@googlegroups.com
I put together a quick script and ran it on a free Gmail account to check. It worked fine. I was able to retrieve the key-value pairs with no problems.

So not sure why you are having this issue, unless there is some other code elsewhere which is doing something it should not.

Do you use the setProperties method somewhere else? Was reading that if you do that, it wipes out any other key-value pairs that may have existed.


Jean-Luc Vanhulst

unread,
Dec 6, 2020, 6:18:29 PM12/6/20
to google-apps-sc...@googlegroups.com
The problem is when deployed as an add-on and deployed through the google chrome store. 
So it’s not that easy to reproduce. 



Jean-Luc Vanhulst

unread,
Dec 6, 2020, 8:28:10 PM12/6/20
to google-apps-sc...@googlegroups.com

SOLUTION FOUND!! -> TRICKY!

So I wanted to start from scratch again and went into the google account I used to remove the add-on. Since it could ALSO not save data in the spreadsheet. 

Just FYI - the plug in was installed from the official Chrome site ( https://gsuite.google.com/marketplace/app/import_oura_ring_data_into_google_sheets/1083644127886 ) AND the Oauth screen, asking for confirmation pops up has already been GRANTED! 

Under security I noticed this:

image.png
And it said "Requested" - not recognized. Clicked on the arrow and confirmed 'yes it was me' - and guess what ? The API key shows up.

So what happens is that eventhough the user authorizes the app explicitly - some other security features denies access without making clear why/how. 

I will add this to my user manual :)

CBMServices Web

unread,
Dec 6, 2020, 8:31:36 PM12/6/20
to google-apps-sc...@googlegroups.com

Alan Wells

unread,
Dec 6, 2020, 8:57:53 PM12/6/20
to Google Apps Script Community
Glad to know it's not a Apps Script bug.
Thank you for posting that you found the problem.

Jean-Luc Vanhulst

unread,
Dec 6, 2020, 9:02:46 PM12/6/20
to google-apps-sc...@googlegroups.com
I'm not sure I would not call it a bug. There's is no exception thrown, the user (and the developer) think the app is authorized (and went through the Oauth screen) but it's not working.

Alan Wells

unread,
Dec 6, 2020, 9:13:16 PM12/6/20
to Google Apps Script Community
Yes, good point.
If it is a bug, and you create a new issue, then I'd like to know about it so that I can stay updated.
Reply all
Reply to author
Forward
0 new messages