Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Help with building a Relationship to query RITM variables

Steve8
Tera Contributor

I am trying to reuse some code I found on another post for building relationships. I am still learning scripting. But I fear trying to query off RITM variables is tossing me for a loop and I could use some help. My goal is to build a related list for my facility table to show all request items that have the facility selected in the RITM's variable field site_location_1 or site_location_2. Ideally I dont want to have to define the catalog item specifically, because I have many catalog items that use this field name. But if I do, would need to build an array of cata item names.

 

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
	var ritms = [];
	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('cat_item.variables.site_location_1',parent.sys_id);
	gr.addQuery('cat_item.variables.site_location_2',parent.sys_id);
	gr.query();
	while(gr.next())
		{
		ritms.push(gr.getValue('sys_id'));
		}
	
	current.addEncodedQuery(ritms);

})(current, parent);

 

find_real_file.png

1 ACCEPTED SOLUTION

Steve8
Tera Contributor

I played around with the code some and got this working. Thank you for the help!

 

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
	var ritms = [];
	var gr = new GlideRecord('sc_req_item');
	gr.query();
	while (gr.next()) {
		var siteLoc1 = gr.variables.site_location_1;
		var siteLoc2 = gr.variables.site_location_2;
		if (siteLoc1 == parent.getValue('sys_id') || siteLoc2 == parent.getValue('sys_id')) {
			ritms.push(gr.getValue('sys_id'));
		}
	}
	current.addQuery('sys_id', ritms);
})(current, parent);

View solution in original post

5 REPLIES 5

Thanks for the update, Steve. Would you mind marking my response as helpful/correct if I am able to resolve your query? thanks

 

- Pradeep Sharma