- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 06:14 AM
Hi,
We have a reference field(ex: sys_user). Based on that reference table, we are populating details in other field. Now if the user doesn't have mobile number in User table we are setting that field value as NA. If the user has mobile number then it will populate in the field. Now the script is fine if the user is having mobile number but not setting to NA if mobile number is empty. This is a simple script but not sure why it is not working.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var test =g_form.getReference("name_of_the_student",user);
function user(test){
var mob= "NA";
if(test.mobile_phone!=" ")
g_form.setValue("mobile_number",test.mobile_phone);
else if(test.mobile_phone==" ")
g_form.setValue("mobile_number",mob);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 06:23 AM
update as this
you should be comparing like this to check if it has value
if(test.mobile_phone)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var test = g_form.getReference("name_of_the_student",user);
function user(test){
var mob = "NA";
if(test.mobile_phone!="")
g_form.setValue("mobile_number",test.mobile_phone);
else
g_form.setValue("mobile_number",mob);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 06:23 AM
update as this
you should be comparing like this to check if it has value
if(test.mobile_phone)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var test = g_form.getReference("name_of_the_student",user);
function user(test){
var mob = "NA";
if(test.mobile_phone!="")
g_form.setValue("mobile_number",test.mobile_phone);
else
g_form.setValue("mobile_number",mob);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 06:46 AM
Thanks @Ankur Bawiskar .
Can you just tell me the difference between the script you shared and my script.