arrayutil

nikhilgadodiya
Kilo Contributor

Hi community,

i am using a transform map to add IT Owners in a list type field as follows :

it owner.PNG

but evry time i run i get duplicate entries added please guide me to avoid that.

thanks in advance

6 REPLIES 6

Mike Allen
Mega Sage

This is just a comma-separated string, so in your transform map, you can do something like this:



var arrayUtil = new ArrayUtil();


var targetList = target.u_it_owners;


var sourceList = source.u_it_owners;



var sourceListArray = new Array();


sourceListArray = sourceList.slice(',');



var targetListArray = new Array();


targetListArray = targetList.slice(',');



var newListArray = new Array();


for(var i=0; i<listArray.length; i++){


        if(arrayUtil.indexOf(targetListArray, listArray[i]) == -1){


                  newListArray .push(listArray[i]);


        }


}



target.u_it_owners += newListArray.toString();


srinivasthelu
Tera Guru

Hi Nikhil,



Are you trying to add to it to the existing list? . What is the expected Source Field value? Comma separated String with Sys_ids? If yes, Below should work. If not please describe more?



var arrayUtil = new ArrayUtil();


var targetList = target.u_it_owners.split(',');


var sourceList = source.u_it_owners.split(',');



resultList=arrayUtil.concat(targetList,sourceList);



target.u_it_owners=resultList.join(',')



Thanks


Srini


Hi Srini,


Actually I am trying to add to existing list where some users are already present.I want to first match whether user is already present in IT Owners list or not if it is present then I will ignore him or else I will add him.



I tried solution provided by you earlier but it is not working.


Please assist me through it.


Nikhil:



Something like this?



var ownersList = u_it_owners.split(',');


u_it_owners = new ArrayUtil().unique(ownersList);



See if that works.



Steven.