
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2015 01:14 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2015 01:24 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 05:54 PM
Hello again Berny,
Im currently working on some Transform Scripts and there's a few places where im a bit confused or not clear on where the scripts on a transform operate. Ive reviewed the wiki and Im still a bit unclear on things. I was hoping to get a bit of help from the community and decided to post here instead of creating a new thread.
I want to make a clear picture/diagram of how the scripts work in a Transformation. Im listing the events in the order I think they get executed by SN. I will be referring to the following image in order to visualize things better:
Quotes taken from http://wiki.servicenow.com/?title=Transform_Map_Scripts#gsc.tab=0
1. onStart() "When: The onStart event script is processed at the start of an import run, before any data rows are read."
- Per the image above, Im thinking onStart() would be between the "External Data Sources" and the "Import Set Table". Before anything is read and brought into the Import set Table.
2. onBefore() When: "The onBefore event script is processed at the start of a row transformation, before the source row is transformed into the target row."
- Assuming the source (GlideRecord Object) is essentially a reference to the Import Set Table. This step would be between the "Import Set Table" and the "Transform" section. The only reason I place this here, before the Field Map Script, is because in this script you can work on either the source or target object.
3. Field Map Script "The field map determines what values from the source table the transformation adds to the target table." "answer - The field value to set in the target record." Creating New Transform Maps - ServiceNow Wiki
- This is the script inside of the Transform itself. I place this after the onBefore() because the answer variable is what gets placed into the target table. Meaning, if for a specific field, for which you are running a Field Map Script on, you leave answer blank, the value imported to the target (and displayed after the transform) will be blank. Im not sure if you could still set the target's value from the onBefore() script, and thereby having the onBefore() map execution being AFTER the Field Map Script.
4. Field Map Determines the relationships between fields in an Import Set Table and fields in an existing SN table.
- This is just your regular field mapping either done automatically by the Auto Map Matching Fields or Mapping Assist tools.
5. Explicit Transform Map Script When: "It runs in the context of "after" the source field values have been copied over to the target record, and before they are written to the database."
- The key for me here is that it runs before the database is written to. Heres what's confusing: The target record. If this is before the database is written to, then what is the target record? I thought the target record, was a record inside of the target database. Does this mean that the target object in the script is a table that is holding values before they are sent to the Database itself?
6. onAfter() "When: The onAfter event script is processed at the end of a row transformation, after the source row has been transformed into the target row and saved."
- From my own experience in scripting, I think this is after the target record in the database has been written to. I have been able to update the same table & row the Transform Map was writing to and had the table display the value I set on this script. If you look at the definition on "When" for the Explicit Transform Map, its a bit confusing as to how the data is actually being written to the Database itself and where everything is placed.
7. onComplete() "When: The onComplete event script is processed at the end of an import run, after all data rows are read and transformed."
- Pretty self explanatory.
I GUESS I HAVE THE FOLLOWING QUESTIONS:
1. Is my understanding above correct? In particular #s 3, 5, & 6. Im not sure im understanding correctly
2. Is there some sort of intermediary table that the Transform is saving records to before saving to the actual Database?
3. The "target" variable in all scripts, is this a direct reference to the target table record? Or is this simply and object living in the script scope?
4. When dealing with things like Date/Time objects, any data manipulation by SN, such as converting UTC to Display Values, where exactly in the process is that taking place?
5. Im not sure where onReject, onChoiceCreate, or onForeignInsert
Im sorry Berny, I dont mean to put this all on you. If you prefer, I can create a new thread and ask the greater community at large. Any insight is always appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2016 12:02 AM
Hi Nestor,
Glad to see you're trying to understand this in depth. I'm answer based on what my understanding is and will try to cover as much as possible the different questions that you have.
First I will like to point out that all transform scripts are actually executed at the transform stage [the blue vertical bar on your diagram]. In other words, even from the onStart transform script the data has already been imported into the "stage" import set table.
Second, the target object is exactly that, an object . And yes, it leaves on the context of all the scripts taking place on that transformation. In other words, it holds data in memory. If another script / user in another session tries to access the data within the target table at any step for a table which is on the process of a transformation before the onAfter transform script then the script / user in the other session will not be able to see the most updated version of that record.
Third, any casting (variable conversion) will take place at the assignment to the target object.
On regards the other transform scripts, I'll try to provide some explanation to these:
onReject: imagine we're trying to import a user and trying to associate to it a new company which creation fails because perhaps it was halted due to an onBefore business rule at the company table. On this case the onReject transform script will be fired.
onChoiceCreate: this gets executed when a new choice is added on the transform. This transform script is triggered before the choice value is created in case there's any preparation, clean-up, preconditions, etc... for the new choice to properly exist.
onForeignInsert: similar situation as the one explained on the onReject scenario but on this case this transform script gets executed right before the record is created. I will think that from an order of execution if an onForeignInsert transform script was triggered it's already past the point where the onReject transform script could possibly be triggered for that record.
I hope this helps!
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2016 12:04 AM
btw... I should have added. These were great questions! Thanks for raising them and keeping these on this thread for others to reference to them on the future.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2015 12:03 AM
Hi Ravio, do you feel that your question has been answered? If yes, please consider marking the responses as helpful/correct so that we can close this thread.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2017 06:51 AM
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
you can refer this link Validating the order of execution for transform map scripts