Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

variable set fields value in catalog item

Ankita9793
Tera Contributor

Hi All,

 

How to get beneficiary's(user filed in variable set) location in a catalog item field?

OnChange client script

 

 

 

Ankita9793_0-1702904590354.png

 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita9793 

on change of beneficiary what you want to set?

what's not working? what debugging have you done so far?

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

Dr Atul G- LNG
Tera Patron
Tera Patron

HI @Ankita9793 

 

What you want to achieve? Please provide more details about same to guide you better.

*************************************************************************************************************
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]

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

SunilKumar_P
Giga Sage

Hi @Ankita9793,

 

You can use the GlideAjax to populate the user country. Please try the below script.

 

Script Include:

 

var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getUserLocation: function(){
        var userID = this.getParameter('sysparm_user');
        var userGr = new GlideRecord("sys_user");
        if(userGr.get(userID)){
            return userGr.u_country;
        }
    },
    type: 'GetUserDetails'
});
 
Client Script:
 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var ben = g_form.getValue('beneficiary');
    var ga = new GlideAjax('global.GetUserDetails');
    ga.addParam('sysparm_name', 'getUserLocation');
    ga.addParam('sysparm_user', ben);
    ga.getXML(getLoc);

    function getLoc(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('user_location', answer);
    }

}
 
SunilKumar_P_0-1702906896252.pngSunilKumar_P_1-1702906914269.png

 

 

Regards,

Sunil