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

Alikutty A
Tera Sage

Hello Shaik,

You can change the Type of Variable to Lookup Select Box and make sure you check unique values only under Type Specifications.

find_real_file.png

Please try and let me know

Thanks

Cant we implement the same on Reference type ?

You will need to write a advanced scripted reference qualifier to remove duplicates and display it on the reference variable. This is not a recommended approach, You should not allow duplicate group names on your group table and prevent it from creation by marking the unique flag on the name column on sys_user_group table.

 

siva_
Giga Guru

May i know What is the reason you have multiple group names with same name?

Thanks,

Siva