OnChange Client script

KS13
Tera Contributor
Hi,
Hoping someone can help with an onChange catalog lient script. 
I have a reference field 'app_mne' that references the Business App table in ServiceNow.
I have another single line field 'LOB' which needs to auto-populate from the above table that contains a field  'Abc_can' on the table. 
 
Any help is appreciated. 
Thanks
 

 

2 ACCEPTED SOLUTIONS

Danish Bhairag2
Tera Sage
Tera Sage

Hi @KS13 ,

 

Please try the autopopulate functionality in servicenow where u can just do this work without using a single code. 

Autopopulate feature works from Utah version.

 

Please check this link for detailed steps

https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-referenc...

 

Thanks,

Danish

 

View solution in original post

Community Alums
Not applicable

you cant have cat.variable/field name having upper case letters in the "system" name.Also,not best idea using catalog client script when you can use "auto populate" -super easy to use and mega fast performance wise.

 

View solution in original post

7 REPLIES 7

Danish Bhairag2
Tera Sage
Tera Sage

Hi @KS13 ,

 

Please try the autopopulate functionality in servicenow where u can just do this work without using a single code. 

Autopopulate feature works from Utah version.

 

Please check this link for detailed steps

https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-referenc...

 

Thanks,

Danish

 

Community Alums
Not applicable

agree fully here

 

Sainath N
Mega Sage
Mega Sage

@KS13 : Please use the below code and replace variable names as necessary

function onChange(control, oldValue, newValue, isLoading) {
    g_form.getReference('app_mne', doAlert); // doAlert is our callback function
}
 
function doAlert(app) { // reference is passed into callback as first arguments
   if (app.getValue('Abc_can') ) {
      g_form.setValue('LOB', app.getValue('Abc_can'));
   }
}

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

 

KS13
Tera Contributor

Unfortunately this did not work!