- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2015 05:27 AM
I have a table 'xyz' which contains redundant values suppose like name
xyz
Name company
---------- -------
John Google
Mark Microsoft
John Google
when I give choice table as xyz and choice field as 'Name' im getting John,Mark,John but I need only one John.
like John,Mark
Is there any way to get it without changing xyz table dictionary (in wiki we have unique id concept but that is field dictionary but I need redundant values in 'xyz' table).
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2015 03:00 PM
Hi Vamsi, just in case it helps, there's various post that recommend using an array, yet, i believe a hash is the best way to go in terms of performance to get unique values. Below I add an example where I collect all the unique states from the incidents table:
var myStatesHash = {};
gr = new GlideRecord('incident');
gr.query();
while (gr.next())
{
myStatesHash[gr.state] = gr.state.getDisplayValue();
}
var state = '';
for (state in myStatesHash) {
gs.print(state + ' : ' + myStatesHash[state]);
}
Just in case you want to look to the array options:
pull only distinct values - This is a good one for you as well since it does the same thing you're trying to accomplish
Also, there's an arrayUtil which has a .unique function: http://wiki.servicenow.com/index.php?title=ArrayUtil#gsc.tab=0
I hope this is helpful! Cheers!
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2015 12:17 PM
You will need to create a script include and use a dynamic reference qualifier.
http://wiki.servicenow.com/index.php?title=K12_Advanced_Scripting#Script_Include_-_Lab_2&gsc.tab=0
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2015 03:00 PM
Hi Vamsi, just in case it helps, there's various post that recommend using an array, yet, i believe a hash is the best way to go in terms of performance to get unique values. Below I add an example where I collect all the unique states from the incidents table:
var myStatesHash = {};
gr = new GlideRecord('incident');
gr.query();
while (gr.next())
{
myStatesHash[gr.state] = gr.state.getDisplayValue();
}
var state = '';
for (state in myStatesHash) {
gs.print(state + ' : ' + myStatesHash[state]);
}
Just in case you want to look to the array options:
pull only distinct values - This is a good one for you as well since it does the same thing you're trying to accomplish
Also, there's an arrayUtil which has a .unique function: http://wiki.servicenow.com/index.php?title=ArrayUtil#gsc.tab=0
I hope this is helpful! Cheers!
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 12:33 AM
Thank you so much Berny
It resolved my issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 12:34 AM
Awesome!!