How do I dynamically update Service Catalog reference fields based on a selection in another reference field?

Evan McElfresh
Giga Guru

On the below request form from our service catalog, I would like the group of text boxes / reference fields to auto-fill based on the user data from the first reference field. I have been seeking an onChange Catalog Client Script / Script Include to get this done, but have had no success. Any help is appreciated.

find_real_file.png

Please mark this response as correct and/or helpful if it assisted you with your question.
1 ACCEPTED SOLUTION

Evan McElfresh
Giga Guru

I figured it out!

The key was this small bit of code, which passes the, "newValue" variable to the sysparm_state variable.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax("ASHNUserDetailsUtil");
    ga.addParam("sysparm_name", "user_info");
    ga.addParam("sysparm_state", newValue);
    ga.getXML(ajaxResponse);

 

Catalog Client Script

find_real_file.png

Script Inlucde: Client callable

find_real_file.png

Please mark this response as correct and/or helpful if it assisted you with your question.

View solution in original post

3 REPLIES 3

Saurabh S
Giga Guru
Giga Guru

This is a clear case of executing server side data from client side where you have to pull the user's info from the sys_user table as soon as the employee name is entered in the first reference field.

Instead of the on change client script, please use GlideAjax which passes parameters to the script includes, and, using naming conventions, allows the use of these parameters.

 

The below docs article from ServiceNow should be helpful.

https://docs.servicenow.com/en-US/bundle/tokyo-application-development/page/script/ajax/topic/p_AJAX.html

 

Please mark my answer correct/helpful if it helped you in any way. Thanks

Thank you. This got me closer, but I'm still not quite to my requirement yet. I now am able to populate data into the form automatically, but there's two problems, with screenshots below.

1) The user info being populated is the logged in user. The template I worked from was built to accomplish this, so I'm not shocked there, but I can't find a solution to instead have the reference be from my Reference Field, "employee_to_be_terminated"

2) I am getting data onLoad, but it should only be onChange

 

Script Include:

find_real_file.png

 

Catalog Client Script

find_real_file.png

 

 

Please mark this response as correct and/or helpful if it assisted you with your question.

Evan McElfresh
Giga Guru

I figured it out!

The key was this small bit of code, which passes the, "newValue" variable to the sysparm_state variable.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax("ASHNUserDetailsUtil");
    ga.addParam("sysparm_name", "user_info");
    ga.addParam("sysparm_state", newValue);
    ga.getXML(ajaxResponse);

 

Catalog Client Script

find_real_file.png

Script Inlucde: Client callable

find_real_file.png

Please mark this response as correct and/or helpful if it assisted you with your question.