- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2019 01:38 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2019 11:02 PM
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();
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2019 06:19 AM
Variable name is Center & Cost Center table field name is name.
Do i need to change in Scirpt Include & Ref Qualifier or only Ref Qualifier ?
Variable Name:
Cost Center whcih is a Referring table:
Advanced Script:
Script Include: I tried keeping as Center too but it is not working in the scriptinclude function and unique field script line

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2019 06:27 AM
I missed this in the code Irfan
----------------------------------------------
var arrayUtil = new ArrayUtil();
var store = arrayUtil.unique(duplicateFieldName);
return 'sys_idIN'+store.toString();
--------------------------------------------
Mark the answer as correct and helpful if it helped you..!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2019 07:06 AM
Thank you, Now i dont see any record all gets disapperead 😞
Script Include:
var ScriptIncludeName = Class.create();
ScriptIncludeName.prototype = {
scriptIncludeFunctionName: function(duplicateFieldName) {
var arrayUtil = new ArrayUtil();
var store = arrayUtil.unique(duplicateFieldName);
return 'sys_idIN'+store.toString();
},
type: 'ScriptIncludeName'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2019 06:20 AM
Hello Irfan ,
The way you called the script include in the reference qualifier is correct but the thing which you are missing is
after doing the processing that needs to be done in script include you are getting the items into an array but you are not filtering the duplicates as expected (i mean you are directly returning the array with the names from your script include and that doesnot work)
To make it work , you have to get the sys ids as an comma seperated list of values as you are returning the values to a reference field , it can only display records based on the set of sysid's
so into your array you can get set of sys_id values and you can use Array.join() after the ArrayUtil.unique() line
and assign those values to a variable and while returning you can use return "sys_idIN"+varName
Hope that helps
Thanks,
Siva
MARK THIS RESPONSE AS CORRECT IF THAT REALLY HELPS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2019 07:07 AM
In above response am i missing anything ?