- 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 10:57 PM
Just change the function to this and it should work
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 = [];
var cc1 = new GlideRecord('cmn_cost_center');
cc1.addEncodedQuery('nameIN'+uniqueArr.toString());
cc1.query();
while(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 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 11:47 PM
Definetely agree that duplicates should not be allowed at the table level but Ali bro i have a question for you
Are we sure everytime we will have the same set of sys ids in uniqueArr ?
Thanks,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2019 05:02 AM
@Siva, This is why it is not recommended, As long you are you are only interested in the unique cost center labels, it should be fine. If you need to access other data from this table or related reference field, then you need to make sure that data is synchronized. The references may not work though
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2020 04:39 AM
Hello,
I have used similar script to get unique list of users but I am getting output like
sys_idIND, L, V, W, G, H, E, z, M, o, Z, N, I, A, y, K, g, S, w, R, s, d, h, i, n
What changes should I make in order to get users list.
Thanks in advance