0

New js-er here so appreciate the support. I am passing an object array, userInfo{}, which has the following contents :

{"userName":"bob","userID":12345,"userDetail":1} from a client-side JavaScript using google.script.run.userClicked(userInfo).

Have used JSON.stringify() in an alert box to make sure the object array being passed is in the above format and then on the server side I am able to use the data when writing to a googlesheet cell.

e.g. ss.getRange(2, userInfo.userID).setValue(userInfo.userName).

This works fine.

My issue is when I want to use userInfo data in the server side script as a parameter:

e.g. var newUserDetail = userInfo.userDetail + 5; or if (userInfo.userDetail = 1) {perform action} etc.

The script does not respond. Do I need to transform the object array elements somehow ? Or use a different syntax to userInfo.userDetail ?

Have searched for on variants of how to access variables passed from client side to server side in js/gs' with no success. I am sure this is super-obvious but still learning - so all help appreciated.

3
  • Can I ask you about the detail of The script does not respond.? Commented Jun 14, 2022 at 6:01
  • Yes, sorry - poor level of detail. For the if statement for example - using: if(userInfo.userDetail = 1) {perform action} then it will perform action irrespective of whether userDetail is 1 or not… Commented Jun 14, 2022 at 6:22
  • Thank you for replying. About For the if statement for example - using: if(userInfo.userDetail = 1) {perform action} then it will perform action irrespective of whether userDetail is 1 or no, if you doesn't miscopy your script, I think that if(userInfo.userDetail = 1) is required to be if(userInfo.userDetail == 1). How about this? Commented Jun 14, 2022 at 6:24

1 Answer 1

2

The issue might be the way you are writing the condition inside of your if statement. In javascript, to compare two values you should use either == or ===.

== is used to compare two values regardless of their types, for example console.log("22" == 22) will print true. While console.log("22" === 22) will print false.

You mention your if statement having the condition userInfo.userDetail = 1, while it should be userInfo.userDetail === 1

Sign up to request clarification or add additional context in comments.

2 Comments

Exactly this - thanks Deor, appreciate!
If this helped answer your question please mark my post as the answer :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.