- 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: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 01:14 AM
did you check what came in alert?
I believe your onchange is written on department variable
Are you sure the platform name is correct and the sap choice value is correct? Any spaces in the choice value?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var st = g_form.getValue("department");
if (st == "5d7f17f03710200044e0bfc8bcbe5d43")
{
alert('inside if');
g_form.setValue("platform", 'sap');
}
//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 07:20 PM
Hope you are doing good.
Did my reply answer your question?
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