need to clear before run an import of new data

User149490
Tera Contributor

Hi,

I need to clear the values from a field in a table (or set to 0) before I run the Import Set to update the data.

I have a table with different entries and stock values. I have also a import set to update the stock values with ne entries but in the update list are not all entries available. So my plan was to set all stock values to null before I run the import set, but I don ´t know how.

Thats why I need your help.

Best regards

André

1 ACCEPTED SOLUTION

palanikumar
Mega Sage

You can run the following script before your import:



var gr = new GlideRecord('your_table');


gr.addQuery();


gr.query();


while (gr.next()) {


          gr.u_field_1 = 0;


          gr.u_field_2 = 0;


          gr.update();


}



If you have this import set scheduled, then you can include this code in "Execute pre-import script" section.


Thank you,
Palani

View solution in original post

6 REPLIES 6

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Andre,



You can use a script like this in Background Scripts:



var gr = new GlideRecord('yourtablename');


gr.query();



while(gr.next()){


  gr.yourfieldname='';


  gr.update();


}




Depending on how big your table is, this script might run for a long time.



Regards,


Hi Sergiu,



thanks for your help but I need a way to do this automatically before I run the Scheduled import set. Maybe you can me help again?



regards


André


Hi Andre,



You can execute a scheduled job to clear import sets 15/30mins before your actual scheduled import.


Also check whether the following Scheduled Job "Import Set Deleter" is present and active in your instance if yes check the timing and set it as per your needs. If not then create one with the below script



var ic = new ImportSetCleaner();


// delete import sets and their related import set rows


// that were created more than or equal to 7 days ago


ic.setDaysAgo(7);


ic.clean();



Mark Correct if this solves your issue or hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Andre,



What about an "onStart" script in the transform map?



http://wiki.servicenow.com/?title=Transform_Map_Scripts#gsc.tab=0



The onStart event script is processed at the start of an import run, before any data rows are read.