Get the value of the related list by Gliderecord

RyoyaFukuda
Tera Contributor

Hi, all.
I would like to use gliderecord to retrieve a value from a related list of a certain record.
How can I achieve these?
I would be glad to know about even the smallest things.

1 ACCEPTED SOLUTION

Harshal Aditya
Mega Sage
Mega Sage

Hi @RyoyaFukuda ,

 

Hope you are doing well.

 

For example - I am in an incident record and want to fetch short description of all the incident_task records in its related list

 

(function executeRule(current, previous /*null when async*/) {

	var getIncTask = new GlideRecord("incident_task");
	getIncTask.addQuery("incident",current.sys_id);
	getIncTask.query();
	while(getIncTask.next()){
		gs.addInfoMessage(getIncTask.short_description);
	}

})(current, previous);

 

The code will be more or less similar to that of other requirements as well

 

Please mark this response as correct or helpful if it assisted you with your question.

Regards,
Harshal

 

 

View solution in original post

3 REPLIES 3

Harshal Aditya
Mega Sage
Mega Sage

Hi @RyoyaFukuda ,

 

Hope you are doing well.

 

For example - I am in an incident record and want to fetch short description of all the incident_task records in its related list

 

(function executeRule(current, previous /*null when async*/) {

	var getIncTask = new GlideRecord("incident_task");
	getIncTask.addQuery("incident",current.sys_id);
	getIncTask.query();
	while(getIncTask.next()){
		gs.addInfoMessage(getIncTask.short_description);
	}

})(current, previous);

 

The code will be more or less similar to that of other requirements as well

 

Please mark this response as correct or helpful if it assisted you with your question.

Regards,
Harshal

 

 

Bert_c1
Kilo Patron

Hi,

 

Here's an example:

 

// show related list (watch_list) values for indicents
var incRec = new GlideRecord('incident');
incRec.addEncodedQuery('watch_listISNOTEMPTY');
incRec.query();
gs.info("Found " + incRec.getRowCount() + " records to process.");
while (incRec.next()) {
  gs.info("Incident: " + incRec.number + " watch_list = " + incRec.watch_list + ".");
}

That returns all incident records where watch_list is not empty. Your query will be on what is a "certain record".

Ankur Bawiskar
Tera Patron
Tera Patron

@RyoyaFukuda 

so what did you start with and where are you stuck?

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