Transform Map run script syntax won't work in onAfter/onBefore ?

Nolan4
Tera Contributor

The syntax --> target.city = source.u_city + "(" + source.u_state + ")"; works in run script of a transform map but when I try to run the same syntax through onBefore or onAfter it doesn't work. 

My question is, is the syntax a bit different in Transform scripts(onBefore or onAfter) than it is in Run script ? i.e. do we need to add any update code? 

I had also tried  if (action == 'insert') {
target.city = source.u_city + "(" + source.u_state + ")";

but didn't work. Please suggest, thanks.

5 REPLIES 5

Jaspal Singh
Mega Patron
Mega Patron

Yes. Since its onBefore or onAfter it will not have current row value & thus all you need is to GlideRecord the target table & set value accordingly.

 

Yes.

What I actually understood is we can just access the values using source. or target. but it doesn't get updated in the target table like it does in the run script. Here we need to do GlideRecord and then update. Didn't understand the reason though!

Sebastian L
Mega Sage

So this is what the onAfter and onBefore does: 

  • onAfter: executes at the end of a row transformation and after the source row has been transformed into the target row and saved
  • onBefore: executes at the start of a row transformation and before the row is transformed into the target row

You can look at this docs site for what you have available at each step. 

 

So your syntax should work onBefore, but not onAfter. 


Best regards,
Sebastian Laursen

Nishu Saini
Kilo Guru
Kilo Guru

Hi Nolan,

 

It should work for "onBefore" can you share your code for onBefore.

Please check the order for the transform map is as below:

  1. Run the onStart script
  2. Find the target record by evaluating all coalesce field maps/scripts.
  3. Before any other scripts are executed, the target record is found.
  4. Run the onBefore script.
  5. Since this is executed after finding the target record, you need to make sure the coalesce scripts do not depend on any variables defined here in the onBefore script.
  6. Transform all field mappings.
  7. Run the main transform Run script.
  8. This is the main script in the transform map which is visible only when "Run Script" is checked.
  9. Run the onAfter script.
  10. Repeat 2-6 for all import set rows.
  11. Run the onComplete script.

Refer to the link for the object available during each script.

Please mark helpful/correct if it resolves the issue.

 

Thanks and Regards

Nishu