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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it would be nice if you share the script you are using

Regards
Ankur

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

Hello Ankur,

 

 

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('sys_id', user);
gr.query();
if (gr.next) {
var json = new global.JSON();

var obj = {

'ucity': gr.getDisplayValue('city'), // in place of city what is the field name have to pass
'ucountry': gr.getDisplayValue('country') // same for country too

};
var data = json.encode(obj);
return data;
}

},

type: 'displaydetails'
});

Hi,

since you are saying city is from location table you can do this

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('sys_id', 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

Sourabh26
Giga Guru

Hi,

 

What I understood is you wanna get the city and location from user table then below are the changes -

 

var obj = {

'ucity': gr.location.city.getDisplayValue();
'ucountry': gr.location.country.getDisplayValue();

};

 

Mark this as Helpful/Correct, if Applicable.

 

Regards,

Sourabh