onafter transform script

Priya123
Tera Contributor

I  need to write a onafter transform script to update a couple of Fields after the import / transform. But i do see one option is via Glide... but i would not have a specific way to search every record  to update the same .. is there a better way to perform this operation as i need to update a couple of fields after every Row is completed

 

sample: i need to update the status and state fields based 2on the dates imported

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Hi,

In the documentation for the onAfter script, you can see that you have access to source and target. Target is equivalent to a GlideRecord for the row that was just transformed: https://docs.servicenow.com/bundle/vancouver-integrate-applications/page/script/server-scripting/ref... 

 

So if you needed to update the ServiceNow record associated to that transform, you can use example:

target.field_name = "Hello";
target.field_name2 = "Test";
target.update();

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Tried this but doesmnt seem to work right 

I need to check for conditions before updating, so i used

 

on the customer project table 

if (target.<datefield value> > sysDate )

{

target.phase == 'value to be updated'

}

 

am trying this way as there is no specific way to search for records using Glide

Hi,

Have you done any logging to see what your values are?

What is "sysDate"? Is that a variable within your script that you're defining? Is it a field from the source import? If so, then you'd need to use:

if (target.field_name > source.field_name) {
target.phase == 'value to be updated';
target.update();
}

Unfortunately, your reply doesn't have a lot of information in it, but if you're needing to compare fields, especially date or date/time fields, they need to be in the same format and of the same type when attempting to use > or < .

 

Please try the above, if applicable, and if you're still struggling, please give more information about the fields involved and include ALL of the script that you're using. Your reply above shows that you aren't using target.update()? So then the target is never updated with the phase that you're setting?

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

yes i did and any target. value is coming back undefined. 

So basically in my import , am loading the actual end date (date/time field - work_end --> Value) 

so i do this:

var sysDate = new GlideDateTime(); // to initiate 

if(target.work_end.before(sysDate))

target.phase == 'value'

 target.update();

 

but this doesnt Work right as expected as its not picking the actual date value