- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2021 06:27 AM
Hello All,
I am trying to concatenate two arrays and then eliminating duplicate sys_id's from the result to give me a list of unique sys_id's. However the function 'unique' does not seem to be working for me.
Here is what the script looks like-
(function executeRule(current, previous /*null when async*/) {
var ptask = new GlideRecord('problem_task');
ptask.addQuery('parent',current.sys_id);
ptask.query();
while(ptask.next()){
var prb = new GlideRecord('problem');
prb.addQuery('sys_id',ptask.parent);
prb.query();
if(prb.next()){
var BS = [];
BS.push(prb.business_service.toString());
}
var BS1 = [];
BS1.push(ptask.business_service.toString());
var b_service = [];
var finlist;
var arrayUtil = new ArrayUtil();
b_service = arrayUtil.concat(BS,BS1);
finlist = arrayUtil.unique(b_service);
var finlist1 = finlist.toString();
ptask.business_service = finlist1;
ptask.update();
}
})(current, previous);
Array BS contains - [A, B, C]
Array BS1 contains - [B,C,D]
Expected result - [A,B,C,D]
Current Result - [A,B,C,B,C,D]
Can you please tell me what could be wrong with the script here ?
Thank you
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2021 01:38 AM
Hi Ankur,
The following code finally worked for me. Highlighted the changes I had to make. Thanks for all your help though.
(function executeRule(current, previous /*null when async*/) {
var ptask = new GlideRecord('problem_task');
ptask.addQuery('parent',current.sys_id);
ptask.query();
while(ptask.next()){
var prb = new GlideRecord('problem');
prb.addQuery('sys_id',ptask.parent);
prb.query();
if(prb.next()){
var BS = [];
BS.push(prb.business_service.toString());
}
BS.push(ptask.business_service.toString());
var b_service;
var arrayUtil = new ArrayUtil();
var list = BS.toString();
var array = list.split(",");
var finlist = arrayUtil.unique(array);
ptask.business_service = finlist.toString();
ptask.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2021 08:41 PM
Any update on this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2021 01:38 AM
Hi Ankur,
The following code finally worked for me. Highlighted the changes I had to make. Thanks for all your help though.
(function executeRule(current, previous /*null when async*/) {
var ptask = new GlideRecord('problem_task');
ptask.addQuery('parent',current.sys_id);
ptask.query();
while(ptask.next()){
var prb = new GlideRecord('problem');
prb.addQuery('sys_id',ptask.parent);
prb.query();
if(prb.next()){
var BS = [];
BS.push(prb.business_service.toString());
}
BS.push(ptask.business_service.toString());
var b_service;
var arrayUtil = new ArrayUtil();
var list = BS.toString();
var array = list.split(",");
var finlist = arrayUtil.unique(array);
ptask.business_service = finlist.toString();
ptask.update();
}
})(current, previous);