Client Script - check if reference field is empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2019 08:59 AM
Dear all,
On client script, how to check if the variable (Reference to user table) is empty and set other variable to read only.
Regard,
Hong
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2019 05:29 AM
Can you share whay you've tried then? If I try, instantly it works:
Do be aware, that by default, onChange (Catalog) Client Scripts contain:
if(isLoading || newValue == '') {
The newValue == '' might be in your way, if this script is on that variable. In that case, remove the || newValue == '' part.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2019 06:48 AM
Hi Mark,
I got the same result as using UI Policy.
When I put javascript:gs.getUserID() in the default value then it doesn't work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2019 06:52 AM
Again: Can you share what you have tried?
I just tested what I shared in this topic, works instantly. So what have you setup? Something in your setup is not oke.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2019 09:48 AM
Hi Mark,
Here is what I have set up.
I have created a table name: u_training_database with the following fields.
- User name, reference to the Users [sys_user]
- Training Completed?, True/Fail
I have import a list of users who have completed the training into u_training_database.
I have a Catalog item name: Elevated Privilege Management have the following variable.
- Requested by (Reference to u_training_database and set default value as javascript:gs.getUserID() ).
- Please_acknowledge_receipt_of_training, Multi-choice
If the user (whose name is not in the u_training_database) open the Elevated Privilege Management form, I would to set the variable Please_acknowledge_receipt_of_training to read only and popup message.
Regards,
Hong