- 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 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 06:54 AM
Thank you Willen, it helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2020 06:55 AM
Hi
I see you marked an answer as Correct. As it is the same as mine, but I was half an our earlier, can you please mark mine as correct? Since that is the fair thing to do and discourages duplicate responses.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2020 06:57 AM
Agreed. Inderjit kindly mark Willem's answer correct as the he suggested before me & strangely I see the comment was same.
So, since he answered first kindly mark Willem's answer correct.