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

Actually I didn't missed it Ankur, I have tried that tooo but I'm not getting the values.

If I put the logs in script include, it's not returning any thing

Hi,

Why don't you add some logs and alerts to debug your script?

Also while testing test with user who have all values filled like location, city, country.

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

    details: function() {
        var user = this.getparameter('sysparm_select');
gs.info('1234 Received user :'+user);
        var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id', user);  // use sys_id if passing sys_id
        gr.query();
        if (gr.next) {
gs.info('1234 record found City :'+gr.location.city.toString());
gs.info('1234 record found country :'+gr.location.country.toString());
            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'
});

And try below:

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.getXMLAnswer(UserDetails);

function UserDetails(response){
alert('Received Resp : '+response);
var obj = JSON.parse(response);

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

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

} 

}

 

Please mark helpful and correct if applicable.

Thanks,

Teju D

Hey Teju,

I have tried by adding logs into the script.

The messages I'm getting are

1234 Received user :undefined

1234 record found City :

1234 record found Country :

 

I'm not getting any values in city and country

 

Regards,

Sweety.

Sweety11
Kilo Contributor

How to glide the sys_user table and cmn_location table to get this requirement?

@ Sweety 

Check my above response.

Regards
Ankur

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