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-04-2019 09:02 AM
Hi there,
If the reference is empty, is actually the same as any different variable. So something like:
if(!g_form.getValue('your_variable')) {
g_form.setReadOnly('your_other_variable', true);
}
or
if(g_form.getValue('your_variable') == '') {
g_form.setReadOnly('your_other_variable', true);
}
Question:
Why are you asking to do this with Client Script? You could also do this No Code, through UI Policy + UI Policy Action.
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-04-2019 12:35 PM
Hi Mark,
UI Policy does not work when I put the javascript:gs.getUserID() as the default value in the reference field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2019 01:02 PM
Ah oke clear.
Did you test the code? Did it work or any questions?
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 04:34 AM
Hi Mark,
No, it is not working.