Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Remove element from an array

pennieturner
Mega Guru

Hi

I'm trying to remove 1 element from an array, but I'm a little stuck on how to do it.

I have a watch list where the callers manager gets added it to, so, if the callers manager changes, I need to remove the old callers manager from it.

I've got far:

updateWatchList();

function updateWatchList() {

var oldCallerMgr = previous.caller_id.manager;

var wList = current.watch_list;

var arr = [];

var newWList = [];

arr = wList.split(',');

var i = 0;

for (; i < arr.length; i++) {

  if (arr[i]!= "") {

  var existWList = arr[i];

  gs.log('existWList person is - ' +existWList);

  if (oldCallerMgr != arr[i]) {

  newWList.push(existWList);

  }

  }

}

  gs.log('newwatch list is - ' +newWList); //This seems to be correct

current.watch_list = newWList;

gs.log('my new watch list is - '+current.watch_list);   //it comes out org.mozilla.javascript.NativeArray@13bae85

}

It seems to work barr the current.watch_list - newWList?   I get the org.mozilla.javascript.NativeArray@13bae85 error?

Any help is appreciated

1 ACCEPTED SOLUTION

srinivasthelu
Tera Guru

Hi Pennie,



current.watch_list expects string.   You need to join the array first in LineNumber 22



current.watch_list = newWList.join(',');  


gs.log('my new watch list is - '+current.watch_list);   //it comes out org.mozilla.javascript.NativeArray@13bae85  



Thanks


Srini


View solution in original post

6 REPLIES 6

Thank you all for your help, the easiest one I found to update my code was Srinivas:



current.watch_list = newWList.join(',');



Adding that code in removed the old manager, so I just added a little more code above it to add the new manager and it works a treat



Thank you


shyamsundar1
Giga Contributor

Hi Pennie,



I have the same requirement in which in the oldCallerMgr - I have more than one value how to check that?




Regards,


Sundar