We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Sequence of transform scripts?

Ravish Shetty
Tera Guru

What are the different sequence of transform scripts?

I am interested in

  • Big transform map script
  • Source script in Field map
  • Other transform scripts like on before, on after, etc
1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi Ravio,



Here goes the order on which I believe it executes:



a) onStart


b) onBefore


c) Transform Map Script (right before the update takes place)


d) Fields Mapped Transforms


e) onAfter


f) onComplete



Thanks,


Berny


View solution in original post

23 REPLIES 23

chani
Tera Contributor

The correct sequence of transform map script is:


1. onStart


2. on Before


3. Source Field script


4. Run script, the script we can find after checking the "Run Script" check box.


5. onAfter


6. onComplete



transform map script.jpg




you can refer this link Validating the order of execution for transform map scripts


I think I've searched for this image at least 5 times in the past few years, finally saved it 🙂

mbourla
Giga Guru

A while back I checked this out by adding some logging into all the different transform scripts scripts, to see the order they came out.   Results as follows:



1) onStart script



2) For each record in the import set:


  a) Field maps for coalesce fields


  b) onBefore script


  c) Field maps for non-coalesce fields


  d) Main transform map script (the one you see if you tick the "Run script" checkbox)


  e) The insert/update on the database


  f) onAfter script



3) onComplete script



Which means the onBefore script will know which record is being created or updated, but won't know the final values of the fields in the target record.



I didn't check the onForeignInsert or onChoiceCreate scripts.



Hope this helps!



Regards


Michael


Hi All,



Am having a doubt, whether can we refer source in the OnAfter transform map script, because it will work only after the source record was inserted in the database, so thought to check with you all.



I am trying to do something similar as below in the example, however source field is not copied in OnAfter transform script, Can anyone guide me what is the best approach to do that.



if(!source.u_business_analyst.nil())


  {


  var timecard1 = new GlideRecord('time_card');


  timecard1.initialize();


  timecard1.task = target.sys_id;


  timecard1.category = 'Business Analyst';


  timecard1.user = source.u_business_analyst;       // This field alone not updating for me while inserting a new record and am using this in onAfter transform script.


timecard1.insert();



  }


I use source on an onAfter:



if(source.u_reference_sysid && ((target.priority < 3) || (target.urgency == 0))){


  status_message = 'Only comments are allowed on major incidents.   Any comments or activity log entries have been recorded to the incident.   All other fields have been ignored.';


}