remove duplicates from an array and get unique values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 08:54 PM
var text=[];
text = new GlideRecord("sn_hr_core_hr_tasks_per_case_type");
text.addEncodedQuery("u_task_visibilityLIKE" + topicCat + "^ORu_task_visibilityISEMPTY");
text.addQuery("u_generation_type", "manual");
text.addNullQuery("u_auto_group_pref","test");
text.query();
while(text.next()) {
taskArray.push(text.getUniqueValue());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 09:13 PM
You can use Array Util class available in servicenow
Ex :
var arrayUtil = new ArrayUtil();
delList = arrayUtil.unique(delList);
return delList;
}
Thanks,
Siva
Mark this response as correct if that resolves your query

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 09:15 PM
Ex:
var text=[];
text = new GlideRecord("sn_hr_core_hr_tasks_per_case_type");
text.addEncodedQuery("u_task_visibilityLIKE" + topicCat + "^ORu_task_visibilityISEMPTY");
text.addQuery("u_generation_type", "manual");
text.addNullQuery("u_auto_group_pref","test");
text.query();
while(text.next()) {
taskArray.push(text.getUniqueValue());
}
var arrayUtil = new ArrayUtil();
delList = arrayUtil.unique(taskArray);
gs.print(delList);//it will contain unique ones here
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 09:18 PM
It is the script include,in the code we r returnng the taskarray=[]; to the other script,so i need to avoid the duplicates in the task array itself

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 09:27 PM
yes you can use the same code before returning your value to the client script That should work
if you have any concerns post the script include code completely i can modify it for you
Thanks,
siva