- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 03:53 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 04:39 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 04:22 AM
Hi Pennie,
You might also want to check this http://stackoverflow.com/questions/5767325/remove-a-particular-element-from-an-array-in-javascript
Thanks
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 04:37 AM
- updateWatchList();
- function updateWatchList() {
- var oldCallerMgr = previous.caller_id.manager;
- var currentCallerMgr=current.caller_id.manager;
- var wList = current.watch_list;
- var arr = [];
- arr = wList.split(',');
var index=arr.indexOf(oldCallerMgr);
- if(index>=0)
- {
- arr[index]=currentCallerMgr;
- }
- current.watch_list = arr.join(',');
- }
Hi Pennie,
The above code should work for you;
Hope that helps
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 04:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 04:39 AM
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