remove duplicates from an array and get unique values

Vijay27
Tera Guru

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());

}

19 REPLIES 19

siva_
Giga Guru

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

 

siva_
Giga Guru

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
}

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

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