The CreatorCon Call for Content is officially open! Get started here.

Script lookup condition in flow designer?

Adrienne Kueber
Tera Contributor

Hi,

 

I am trying to script a lookup on asset records associated with a request in my flow.

I have three related lists for consume assets, transfer assets, and request assets associated with catalog tasks that query from the asset table. The related lists are already scripted, but i need to do this scripting in my flow to look up these records if they exist and update them. How can I dot-walk or create a script for looking up these records?

Relationships for rel lists have been inserted below. I'm a bit new to scripting so I am wondering how I can add all of this to one script so it will work for each condition.

 

Request assets:

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
	current.addQuery('request_line', parent.request_item);
	current.addNotNullQuery('request_line');
	

})(current, parent);

 

Transfer assets:

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
	var assets = [];
	var ritm = parent.request_item+'';
	var gr = new GlideRecord('alm_transfer_order_line');
	gr.addQuery('request_line', ritm);
	gr.addNotNullQuery('request_line');
	gr.query();
	while(gr.next()) {
		assets.push(gr.asset+'');
	}
	current.addQuery('sys_id', 'IN', assets+'');

})(current, parent);

 

Consume Assets

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
	var assets = [];
	var ritm = parent.request_item+'';
	var gr = new GlideRecord('consume_asset_task');
	gr.addQuery('parent', ritm);
	gr.addNotNullQuery('parent');
	gr.query();
	while(gr.next()) {
		assets.push(gr.asset+'');
	}
	current.addQuery('sys_id', 'IN', assets+'');

})(current, parent);

 

2 REPLIES 2

Naga Ravindra R
Kilo Sage

Hi @Adrienne Kueber 

 

You can achieve it from an action in FD. Pass the sysiD of request as an inputs into Action.
Inside use Script functionality, Gliderecord the assets. Get those records sys_ids as outputs.
For ex:

var a = inputs.sys_id //sysID of request
var gra = new GlideRecord('table');

gra. addQuery();

//get the records as outputs.
 

After getting outputs, use a lookup action to get the numbers or if you have to do anything.

 

Please reply back if there are any questions.

 

Please mark as correct/helpful. If it helps.

Thank you for your response! Which action would I use to pass the sysid? Would it be a lookup action and place my script as a scripted condition?