Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

onComplete transform script is not working as expected

d_kush
Giga Contributor

Hi,

I am working on Helsinki version of Service Now.

I have a scheduled job which imports data using REST message from some URL and stores in a staging table.

Then I am using a transform map to transform this data into target table.

Here is the issue, I need to delete records from target table which have not been updated from this import.

For this I have given an onComplete() transform form script which should delete unupdated data based on some filter query. but this script is not working as expected. As my understanding it should delete the data matching to filter condition after all the data has been transformed from staging to target table.

inplace of this, this script is deleting data before transformation.

I don't know what is going wrong with this script.

12 REPLIES 12

bernyalvarado
Mega Sage

Hi Deepti,



Perhaps check the logic of your script since it may be deleting more data than what you're intending. Would you like to share more in detail your desired filter logic and your script over here?



Thanks,


Berny


Hi Berny,



Thanks for replying,


Below is my script:



var rec = new GlideRecord('cmdb_rel_ci');


rec.addEncodedQuery('u_source=Asset Insight^sys_updated_on<javascript:gs.hoursAgo(2)');


rec.query();


if(rec.next()) {


rec.deleteRecord();


}


Hi Deepti,



Your problem may be somewhere else because on that script the most you could end up deleting is one record each time is executed.



Thanks,


Berny


That's because you're using an if instead of a while.



Thanks,


Berny