The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to compare and set values using array

now_dev
Mega Expert

Hi All,

I am having two arrays. First with the list of variable name in a catalog and second with the list of field names along with their values(Variable names and field name are same). Now I am comparing both the array to find the list of variables whose name is same as the field name in second array. Once I get the list, I wanted to set those field values in catalog item variables.

Any help would be appreciated.

1 ACCEPTED SOLUTION

It sounds like you just need to go through the array and make the assignments.



for (k in array_a) {


    array_b[k] = array_a[k];


}


View solution in original post

4 REPLIES 4

Chuck Tomasi
Tera Patron

Take a look at ArrayUtil().intersect(). It's built just for this.



http://wiki.servicenow.com/index.php?title=ArrayUtil


Thanks Chuck for the quick reply.



I am able to get the list of item which is common in both the arrays. Let's assume Array A is a list of catalog Variable and Array B is a list of the field name. I also have the values of the fields which are present in Array B. I wanted to set the values of variables to item values of Array B.



E.g If Array B has item 'Description' with value 'abc'. I wanted to assign/set this value in my catalog item variable with the name 'Description'.


It sounds like you just need to go through the array and make the assignments.



for (k in array_a) {


    array_b[k] = array_a[k];


}


If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you