Client Script - check if reference field is empty

hongsok
Tera Contributor

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

8 REPLIES 8

Can you share whay you've tried then? If I try, instantly it works:

find_real_file.png

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

LinkedIn

hongsok
Tera Contributor

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.

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

LinkedIn

hongsok
Tera Contributor

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