
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 04:28 AM
Hi All,
Hope you all are doing well.
I am working on a requirement where I have three checkboxes under the "Environment" label: Dev, UAT, and PROD. The behavior I am trying to achieve is the following:
- If the Application Service is "Business Central - PROD," the "PROD" checkbox should be set as the default value.
- If the Application Service is "Business Central - PREPROD," the "UAT" checkbox should be set as the default value.
I wrote the following client script on the onChange event, but unfortunately, it's not working as expected:
Could you please help me identify any issues with the script or guide me on how I can achieve this functionality? I would appreciate any insights or suggestions you might have.
Thank you for your time and assistance!
Deepika
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 04:37 AM
Hi,
I'm guessing that the Application service is a reference field ?
If so, then your comparison will never evaluate to true, because the value of the field is not the display name (i.e. Business Central - PROD), but it will contain the sysID of the record selected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 05:07 AM
@Community Alums
try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
try {
if (window == null) {
var valuePortal = g_form.getDisplayValue('variableName');
if (valuePortal == 'Business Central - PREPROD') {
g_form.setValue('uat', 'true');
} else if (valuePortal == 'Business Central - PROD') {
g_form.setValue('prod', 'true');
}
}
} catch (ex) {
var valueNative = g_form.getDisplayBox('variableName').value;
if (valueNative == 'Business Central - PREPROD') {
g_form.setValue('uat', 'true');
} else if (valueNative == 'Business Central - PROD') {
g_form.setValue('prod', 'true');
}
}
}
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
01-07-2025 05:07 AM
@Community Alums
try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
try {
if (window == null) {
var valuePortal = g_form.getDisplayValue('variableName');
if (valuePortal == 'Business Central - PREPROD') {
g_form.setValue('uat', 'true');
} else if (valuePortal == 'Business Central - PROD') {
g_form.setValue('prod', 'true');
}
}
} catch (ex) {
var valueNative = g_form.getDisplayBox('variableName').value;
if (valueNative == 'Business Central - PREPROD') {
g_form.setValue('uat', 'true');
} else if (valueNative == 'Business Central - PROD') {
g_form.setValue('prod', 'true');
}
}
}
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
01-07-2025 05:13 AM
Thank you @Ankur Bawiskar ,
This is working as expected.