How to display only unique values from the Reference variable

shaik_irfan
Tera Guru

Hello,

We have a variable Reference Type which is referring to Assignment Group. Our Assignment Group contains duplicate group names ex: Test Group, Test Group, Network, Network

From the Catalog view when the user clicks or search for the Assingment Group we need to display only unique value like if the user types Network, it should display only Network once not multiple

 

How to acheive this

1 ACCEPTED SOLUTION

Last one may not work, This was tougher than I thought, I would really suggest you control the duplicate names at the table level for cost center, This is really not a recommended approach.

I have tested this script and it works, Please try this out

getUniqueCostCenters: function(){
		var ccList = [];
		var uniqueArr = [];
		var ids = [];
		var arrayUtil = new ArrayUtil();
		var cc = new GlideRecord('cmn_cost_center');
		cc.query();
		while(cc.next()){
			ccList.push(cc.name.toString());
		}
		
		uniqueArr = arrayUtil.unique(ccList);
		ccList = [];
		for(var i=0; i<uniqueArr.length; i++){
			var cc1 = new GlideRecord('cmn_cost_center');
			cc1.addEncodedQuery('nameIN'+uniqueArr[i]);
			cc1.query();
			if(cc1.next()){
				ccList.push(cc1.sys_id.toString());
			}
		}
		
		return 'sys_idIN'+ccList.toString();
	},

View solution in original post

40 REPLIES 40

Chalan B L
Giga Guru

Write an Advanced Reference Qualifier and call script include

** Note: Below script is not tested

find_real_file.png

 

find_real_file.png

Chalan,

 

I tried with your script but it is not working :(.

 

Am i missing anything ?

 

Script Include:

 

 

find_real_file.png

 

Reference Type variable referene qualifier:

find_real_file.png

 

 

 

Irfan in the reference qualifier pass the variable name you want to filter the duplicate names.

 

Let me know the backend name of the variable you are trying for ??

 

Mark correct if it helped you..!!!

Regards,

Chalan

Hello Irfan,

 

Any updates here if it helped you could you please mark the answer correct..!!

 

Regards,

Chalan

He is looking to compare all names from group table and remove duplicates in it. So in group table, if you have 100 groups and several duplicates, it should return unique entries in the reference field.