Empty data sources > Prevent transform

Chris P_
Tera Expert

During the night our system import various data sources, but if something went wrong on the side of, for example, a SQL server where data is being imported from, it might occur that an empty Import Set is created.

But this import set gets transformed nonetheless, and with me having onStart transform actions which sets records to inactive followed by a onComplete transform which deletes all inactive records, I end up with empty tables in the morning...

To prevent this I was thinking along the lines of checking if the Source or Import set in the onStart transform script has records and if not sending an ignore=true.

But I can't seem to find an easy way to get the rowcount of the Importset...

Any ideas?

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Use this in the onstart script



var gr= new GlideRecord('sys_import_set_row');


gr.addQuery('sys_import_set',import_set.getValue('sys_id'));


gr.query();


if(gr.getRowCount()==0){


ignore=true;


}


View solution in original post

3 REPLIES 3

Abhinay Erra
Giga Sage

Use this in the onstart script



var gr= new GlideRecord('sys_import_set_row');


gr.addQuery('sys_import_set',import_set.getValue('sys_id'));


gr.query();


if(gr.getRowCount()==0){


ignore=true;


}


Thanks that works.



I just finished my variant on this:


var gris = new GlideRecord(import_set.table_name);


  gris.addQuery('sys_import_set', import_set.sys_id);


  gris.query();


  if (gris.getRowCount() == 0) {


  ignore = true;


  }



sys_import_set_row or import_set.table_name, has the same result, what's the better choice?



Luckily it also prevents onStart scripts with an higher order, so it promptly stops importing


Was looking for a variable or function on the Source or import_set, but I guess using 1 GlideRecord can't hurt either.


Abhinay Erra
Giga Sage

yes importset.table_name is much cleaner and more dynamic.