How to find an intersection of array data in a script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-03-2020 04:16 AM
Hello,
I have two arrays and need to find count of records which these arrays share in common.
Need to place this in a script include and make this as simple as possible.
The array are:
var createCaseRoles = ['sn_customerservice.customer', 'sn_customerservice.customer_case_manager', 'sn_customerservice.customer_admin', 'sn_customerservice.partner', 'sn_customerservice.partner_admin', 'sn_customerservice.consumer', 'sn_customerservice_agent', 'sn_customerservice_manager', 'sn_customerservice.consumer_agent', 'sn_customerservice_manager'];
var my_roles =['sn_customerservice.customer_admin', 'sn_customerservice.partner_admin', 'sn_customerservice.customer_case_manager' , 'snc_internal' , 'admin' , 'sn_customerservice.customer', 'sn_customerservice.partner' ,'security_admin'];
Any idea how to make this as simple as possible with ossible use inside scriprt include, need to call a method in scriot include returning count of records these array share in common.
Appreciate your help,
Milan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-03-2020 04:25 AM
you can use ArrayUtil class function intersect() to achieve this.
var arr = new ArrayUtil();
var arrInter = arr.intersect(createCaseRoles, my_roles); //pass arrays as a paramter.
var count = arrInter.length; //gives the count of common values
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-03-2020 04:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-03-2020 05:05 AM
Thanks a lot, it works in background - script, but not within script include, once calling it (new XXX().YYY()) from scripts - background
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-03-2020 05:10 AM
Hi Milan,
please share your script
If you are having that script include created in custom scope application then you need to use this
var arr = new global.ArrayUtil();
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader