- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2020 06:19 AM
Hi,
I wanted to compare two list fields(u_groups,u_approver_groups) and return the left out value and update the list field "u_approver_groups" with the left out value.
Client Script
function onLoad() {
var requestedBy = g_form.getReference('cmdb_ci',setGroup);
}
function setGroup(requestedBy)
{
var array1=[];
array1=requestedBy.u_groups;//list field contains multiple groups
alert("The array1 is :"+array1);
var array2 = [];
array2= g_form.getValue('u_approver_groups');//list field in change form contains multiple groups
alert("The array2 is :"+array2);
var array3 = [];
for(var i = 0; i <= array1.length; i++)
{
if(array2.indexOf(array1[i]) == -1){
array3.push(array1[i]);
}
}
alert("The array3 is :"+array3);// It returns empty ,I want to return the groups which are present extra in array1
}
But works fine in the below scenario:
function onLoad() {
var array1=['0a52d3dcd7011200f2d224837e6103f2','3cc3c7680b982300cac6c08393673a03','2156c3a80b982300cac6c08393673a7e'];
var array2 = ['0a52d3dcd7011200f2d224837e6103f2','3cc3c7680b982300cac6c08393673a03'];
var array3 = [];
for(var i = 0; i <= array1.length; i++)
{
if(array2.indexOf(array1[i]) == -1){
array3.push(array1[i]);// This returns 2156c3a80b982300cac6c08393673a7e
}
}
}
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2020 06:26 AM
Are you shure the values are typeOf Array? Can you try split them?
For example:
array1=requestedBy.u_groups.split(",");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2020 08:39 AM
Thank you Jaspal for your kind gesture.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2020 08:38 AM
Apology Willem, unfortunately I didn't see the timing.Now , I have marked your answer correct.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2020 06:31 AM
Hi Inderjit,
Try replacing
array1=requestedBy.u_groups;
with
array1=requestedBy.u_groups.split(',');