Trying to return variables to a list collector based on catalogue item selected in a reference field

Steven Watts2
Tera Guru

Hi,

I'm trying to return a list of variables to a list collector based on a selection made in a reference field to the sc_cat_item table. I.e., the requestor selects the catalogue item and the 'variables to be removed' variable only displays the variables attached to that item. See screenshot below.

 

StevenWatts2_0-1679415874951.png

 

I've updated the reference qualifier on the list collector to - 

javascript: 'sys_idIN' + new GetCatItemDetails().getVariables(current.variables.catalogue_item_to_be_updated);

This is calling a script include function - 

getVariables: function(catItem) {
		
		var vars_array = [];
		var getVars = new GlideRecord('item_option_new');
		getVars.addQuery('cat_item', catItem);
		getVars.query();
		while (getVars.next()) {
			var varsSysId = getVars.getValue('question');
			vars_array.push(varsSysId);
		}
		return vars_array;		
	},

Can anyone see where I am going wrong as the variable always comes back with 'No matches found'.

 

Steven

1 ACCEPTED SOLUTION

@Steven Watts2 ,

 

Got it!

Please do this in reference qualifier, it will work 100%:

javascript: 'cat_item=' + current.variables.your_term_variable_name_here;

PRINCE_ARORA_0-1679492866415.png

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

View solution in original post

8 REPLIES 8

Prince Arora
Tera Sage
Tera Sage

@Steven Watts2 ,

 

Can you please try to update the Server code as:

 

getVariables: function(catItem) {

var vars_array = "";
var getVars = new GlideRecord('item_option_new');
getVars.addQuery('cat_item', catItem);
getVars.query();
while (getVars.next()) {
vars_array = vars_array + getVars.sys_id +",";
}
return vars_array;
},

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact. 

Hi,

 

Thanks for you response and assistance. Unfortunately though, the outcome is the same with no matches being returned. 

 

Steven

@Steven Watts2 ,

 

Hope you are doing well!

 

I have checked your variable in the screenshot and I think it is single line text, you need to create the variable as mentioned below or your variable should be reference type variable and that should be referred to "item_option_new" table and you don't need to write any script include, please set the reference qualifier as mentioned in screenshot.

 

PRINCE_ARORA_0-1679477374941.png

 

you can use :  cat_item=current.Variables.YOUR_VARIABLE_NAME

 

I have tried in my PDI and it worked really well, pls check screenshot, I have tried with sys_id harcoded and it provide me the filtered data

 

My variable:

PRINCE_ARORA_2-1679477505926.png

 

Response:

 

PRINCE_ARORA_1-1679477435161.png

 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

 

Hi,

 

Thanks for responding again.

 

It works fine if I add in a hardcoded sys_id, similar to your screenshot, but when I update the reference qualifier to run against the catalogue item stored in my variable I get the same outcome as before - No matches found.

 

I've double checked and the variable name is correct.

cat_item=current.variables.catalogue_item_to_be_updated

 

Regards,

 

Steven