- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 12:17 AM
Hi All,
I have reference field category and a dropdown field field with yes and no on change table. I need to set the drop down value as "yes" when I select a particular record from category field . I have tried the below script but did not get expected result.
Actually I was trying on a different dropdown field that's why I take 8 in the script but actually I need yes as output as mentioned above.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 12:36 AM
the below will work if you are comparing the correct sysId and the correct choice value
Also use == and not === to compare
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var st = g_form.getValue("department");
if (st == "5d7f17f03710200044e0bfc8bcbe5d43") // give correct sysId
{
g_form.setValue("platform", '8'); // give correct field name and choice value
}
//Type appropriate comment here, and begin script below
}
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
02-10-2025 01:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 12:48 AM
Hi @1_DipikaD ,
Can you please try below code?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') { // change '===' to '=='
return;
}
if ( g_form.getValue("department") == "5d7f17f03710200044e0bfc8bcbe5d43") // change '===' to '=='
{
g_form.setValue("platform", '8'); //set the values
}
//Type appropriate comment here, and begin script below
}
If my response finds helpful, please indicate its helpfulness by selecting Accept as Solution and Helpful.
Thanks,
Vaibhav Nikam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 01:05 AM
I correct the script it's working fine.
But drop down value is not changing while I am changing the reference field value , it remains the same
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 01:08 AM
Can you please check and share the backend name of dropdown field and the value you are setting?
If my response finds helpful, please indicate its helpfulness by selecting Accept as Solution and Helpful.
Thanks,
Vaibhav Nikam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 01:36 AM
I am writting ui policy to clear the field vaue. Is it best practice ?