Catalog item Requested for field

GBS
Tera Contributor

Hi, 

 

I'm using the below catalog client script to auto populate the field values of email, phone, cost center, and invoice address. However, if I change the Requested for to another person, the field values are not changed and reflect the previous user details.

 

function onChange(control, oldValue, newValue, isLoading) {
    var getUserDetails;
    var url = top.location.href;

    if ((isLoading && url.indexOf('edit=cart') < 0) || (newValue && newValue != oldValue)) {
        getUserDetails = new GlideAjax('UserUtility');
        getUserDetails.addParam('sysparm_name', 'reqForDetails');
        getUserDetails.addParam('sysparm_user_name', g_form.getValue("requested_for"));
        getUserDetails.getXML(parseResponse);

    }

    function parseResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var userDetails = JSON.parse(answer);

        var address = userDetails[3] + "," + "\n" + userDetails[4] + ", " + userDetails[5] + ", " + userDetails[6] + "," + "\n" + userDetails[7] + ".";
        g_form.setValue("email", userDetails[0]);
        g_form.setValue("phone", userDetails[1]);
        g_form.setValue("cost_center", userDetails[2]);
        g_form.setValue("invoice_address", address);
        g_form.setValue("delivery_address", address);

    }
}
2 REPLIES 2

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @GBS 

 

You can use OOTB Auto populate feature here

 

LearnNGrowAtul_0-1707303821154.png

 

Create 4 variables and one basis of 1st auto populate all 3.

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Jyoti Jadhav9
Tera Guru

Hi @GBS ,

 

You can achieve data auto-population based on Requested for field using OOB Auto-populate tab provided on variable form.

You can refer the URL . It might be helpful for achieving your functionality.

 

Please hit the like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

 

Thanks & Regards

Jyoti Jadhav