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

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

hongsok
Tera Contributor

Hi Mark,

UI Policy does not work when I put the javascript:gs.getUserID() as the default value in the reference field. 

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

LinkedIn

hongsok
Tera Contributor

Hi Mark,

No, it is not working.