how to dot walk in script include

Sweety11
Kilo Contributor

Hi all,

I'm little bit confused, like how to link the fields from 2 different tables.

Ex: sys_user & cmn_location. In user table i can able to see city & country fields but the field names are populating as location for both. In this case I want to get those particular 2 fields from location table. How I do that in script include?

Sys_user > city want to get from cmn_location > city

Need some detailed understanding. Your inputs helps me to do this thing.

Regards,

Sweety.

26 REPLIES 26

I saw the screenshot, and my code should work with this, these fields are not on your form, but dot walked from location reference field and just showing on the user form.

What error you are getting with this code:

var displaydetails = Class.create();
displaydetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
details: function() {
    var user = this.getparameter('sysparm_select');
    var obj = {};
    var gr = new GlideRecord('sys_user');
    gr.addQuery('sys_id', user);
    gr.query();
    if (gr.next) {
        obj.ucity = gr.location.city, // in place of city what is the field name have to pass
        obj.ucountry = gr.location.country; // same for country too
    }
return JSON.stringify(obj);

},

type: 'displaydetails'
});
Best Regards
Aman Kumar

Is my onLoad client script is correct?

function onLoad() {

var user = g_form.getValue('requested_by');

var ga = new GlideAjax('displaydetails');
ga.addParam('sysparm_name', 'details');
ga.addParam('sysparm_select', user);

ga.getXML(UserDetails);

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

var city = obj.ucity;
var country = obj.ucountry;

 

g_form.setValue('city', city);
g_form.setValue('country', country);

}

 

}

The script is right, considering the city and country field on the catalog item is of type string and not reference.

If it is reference, I would suggest use:

g_form.setDisplayValue('city', city);
g_form.setDisplayValue('country', country);

Best Regards
Aman Kumar

I have selected the type as single line text not a reference

then update your script include function as this

Considering user will be typing full name of user

I already shared the script to dot walk location field an hour ago; seems you missed it

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

    details: function() {
        var user = this.getparameter('sysparm_select');
        var gr = new GlideRecord('sys_user');
        gr.addQuery('name', user);
        gr.query();
        if (gr.next) {
            var obj = {
                'ucity': gr.location.city.toString(), // in place of city what is the field name have to pass
                'ucountry': gr.location.country.toString() // same for country too
            };
            return JSON.stringify(obj);
        }
    },

    type: 'displaydetails'
});

Regards
Ankur

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