Make default checkbox true when application selected

Community Alums
Not applicable

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:

 function onChange(control, oldValue, newValue, isLoading, isTemplate) {
     if (isLoading || newValue === '') {
         return;
     }
     if (newValue == 'Business Central - PREPROD') {
         g_form.setValue('uat', 'true');
     } else if (newValue == 'Business Central - PROD') {
         g_form.setValue('prod', 'true');
     }
 }
 

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


 

2 ACCEPTED SOLUTIONS

OlaN
Giga Sage
Giga Sage

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.

 

View solution in original post

@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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

@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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Community Alums
Not applicable

Thank you @Ankur Bawiskar ,

This is working as expected.