Transform Map for Watchlist*

avinash21
Mega Contributor

Hi All

I have a very basic requirement of updating the Watch list of incident with a transform Map. I have created a spreadsheet with two fields incident and Name.

Incident=Used as a Coalesce Field

Name= Email address of users whom should be added in watch list.

abel.tuter@example.com;adela.cervantsz@example.com;aileen.mottern@example.com;alejandra.prenatt@example.com;alejandro.mascall@example.com

I have written script as below

(function transformRow(source, target, map, log, isUpdate) {

      // Add your code here

     

      var name = source.u_name.toString();

      var incident =source.u_incident.toString();

      var split_names = name.split (";");//Breaking the input in a array

      var num_names = split_names.length;

      var sys_id;

     

      for(i=0;i<=num_names;i++)

              {

                      var gr = new GlideRecord('sys_user');

                      gr.get('email',split_names[0]);

                      gr.query();

                      if(gr.next())

                              {

                                      target.watch_list= target.watch_list+";"+gr.sys_id;//Setting the sys_id of each email address

                                      gs.addInfoMessage(gr.sys_id);

                                      gs.addInfoMessage(split_name[0]);

                                     

                              }

                     

                     

              }

})(source, target, map, log, action==="update");

The Data is getting updated but   the data is getting as it is , its not getting processed as per the script.

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Avinash, I'm sure you'll have a lot of responses to this.



Here's my quick glance at it and a couple changes to make.


Change your for loop to be <, not <=, or you will get an extra undefined result


Change your target.watch_list assignment to this



target.watch_list= target.watch_list+","+gr.getValue('sys_id');



watch lists are comma separated, not colon.



(function transformRow(source, target, map, log, isUpdate) {



      // Add your code here


   


      var name = source.u_name.toString();


      var incident =source.u_incident.toString();


      var split_names = name.split (";");//Breaking the input in a array


      var num_names = split_names.length;


      var sys_id;


   


      for(i=0;i<num_names;i++)


              {


                      var gr = new GlideRecord('sys_user');


                      gr.get('email',split_names[0]);


                      gr.query();


                      if(gr.next())


                              {


                                      target.watch_list= target.watch_list+","+gr.getValue('sys_id');


                                      gs.addInfoMessage(gr.sys_id);


                                      gs.addInfoMessage(split_name[0]);


                                   


                              }


                   


                   


              }


View solution in original post

7 REPLIES 7

Hi chuck.,



I am using the same script but it is storing only one value


Hi @Chuck Tomasi ,

Thanks for the script, But when i use the same script, i got another problem that, if i have 3 watch list users to add as A,B,C, it is adding as A,B,C,A(first person name adding twice) for all records, so, i just changed the script like below,

(function transformRow(source, target, map, log, isUpdate) {
var username = source.u_watch_list.toString();
var split_names = username.split (",");//Breaking the input in a array
var num_names = split_names.length;
var sys_id;
var x;
for(i=0;i<num_names;i++)
{
var gr = new GlideRecord('sys_user');
gr.get('name',split_names[0]);
gr.query();
if(gr.next())
{
x= x+gr.getValue('sys_id');
gs.addInfoMessage(gr.sys_id);
gs.addInfoMessage(split_name[0]);
}
}
target.u_watch_list= x;
})(source, target, map, log, action==="update");

pradeepshokeen
Giga Contributor

Hey Guys,



I was able to add multiple values into list field using transform map, but there are still some challenges like it is adding the value which already exist in the database, is there a way to check the value in target field and if it exist we can ignore if not we can add this....



can we use LIKE in if Condition if(target.u_compliance_and_regulatory_requirements LIKE source.u_compliance_o_y_requirements).



any assistance would be really great...



Thanks!!!