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

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

Yadin
Tera Contributor

I can't quite make sense of this script but as commented it seems inefficient.  Another post suggests this for a post cleanup:

var ic = new ImportSetCleaner();
ic._cleanTable(import_set.table_name, 'sys_import_set=' + import_set.sys_id);

Like the OP I want a pre cleanup so data is retained for troubleshooting.  Unfortunately I don't speak SN so I'm unsure how to modify this seemingly simple command to do what is needed.