- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 04:48 AM
Dear community,
Please help me to achieve this. what I want to achieve is to get only unique values from the below 2 variables.
var a = '88034e4497021110b549bfb6f053af6d,1364b04297865110b549bfb6f053af5e' ;
var b = '04034e4497021110b549bfb6f053af73,88034e4497021110b549bfb6f053af6d';
I need to get only the unique values as below
var result = '88034e4497021110b549bfb6f053af6d,1364b04297865110b549bfb6f053af5e,04034e4497021110b549bfb6f053af73';
But am getting as below, which is not correct.
var result = '88034e4497021110b549bfb6f053af6d,1364b04297865110b549bfb6f053af5e,04034e4497021110b549bfb6f053af73,88034e4497021110b549bfb6f053af6d';
Thanks in advance..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 04:58 AM
Hello,
You need to split your result into array and then use unique method of array util
Please refer below background script
var result = '88034e4497021110b549bfb6f053af6d,1364b04297865110b549bfb6f053af5e,04034e4497021110b549bfb6f053af73,88034e4497021110b549bfb6f053af6d';
var arr = result.split(','); // split your string into array first
var arrayUtil = new ArrayUtil();
var arr1= arrayUtil.unique(arr);
gs.log(arr1); // unique array
Please let me know if you need any other help
Thanks,
Valmik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 04:57 AM
just try below
var uniqueResult= new ArrayUtil().unique(result);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 04:58 AM
Hello,
You need to split your result into array and then use unique method of array util
Please refer below background script
var result = '88034e4497021110b549bfb6f053af6d,1364b04297865110b549bfb6f053af5e,04034e4497021110b549bfb6f053af73,88034e4497021110b549bfb6f053af6d';
var arr = result.split(','); // split your string into array first
var arrayUtil = new ArrayUtil();
var arr1= arrayUtil.unique(arr);
gs.log(arr1); // unique array
Please let me know if you need any other help
Thanks,
Valmik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 05:04 AM
Hi Valmik,
Thanks for your valuable reply 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 06:12 AM
Could you please also help me on this
https://community.servicenow.com/community?id=community_question&sys_id=ba82914adbca1150dd886c8e13961905