- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2024 12:08 PM
Hello developers, i have implemented gliderecord to get array. In this array i need a partuclar column as unique values. In short i need to remove duplicate values from array . Any help is appreciated, Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2024 07:40 PM
Hi @servicenow14710,
You need to use the ArrayUtil to get unique elements. It removes duplicate elements from an array.
var uniqueElements = new ArrayUtil().unique(arrayName);
For reference - ArrayUtil
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2024 05:50 PM
Seems you need to provide more details on your goal.
Here's a good resource on getting assistance here:
tips-on-asking-question-on-community
Post your GlideRecord script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2024 07:40 PM
Hi @servicenow14710,
You need to use the ArrayUtil to get unique elements. It removes duplicate elements from an array.
var uniqueElements = new ArrayUtil().unique(arrayName);
For reference - ArrayUtil
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2024 12:51 AM
Hi @servicenow14710 ,
Agree with @Sagar Pagar , you need to use ArrayUtils and then use gliderecord over the array.
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2024 08:35 PM
To remove duplicate values from an array obtained through GlideRecord, you can use JavaScript's Set object.
// Create a new Set object to store unique values
var uniqueValues = new Set();
// Iterate through the GlideRecord results
while (gr.next()) {
// Get the value of the column you want to make unique
var columnValue = gr.getValue('your_column_name_here');
// Add the value to the Set (which automatically removes duplicates)
uniqueValues.add(columnValue);
}
// Convert the Set back to an array
var uniqueArray = Array.from(uniqueValues);
- Set is a JavaScript object that stores unique values. By adding values to a Set, duplicates are automatically removed.
- Finally, you convert the Set back to an array using Array.from().
This way, uniqueArray will contain unique values extracted from the specified column in your GlideRecord results.
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks