Abort transform if all rows are empty

Evren Yamin
Tera Contributor

Hello,

 

I have enabled "copy empty fields" on my transform map. I know this means that all empty values will be copied on the instance.

Thus, is there a way for me to check the value of the columns first and ignore the transform if there is a column where all values are empty on the file being uploaded.

 

Like for example, in this file, all rows for short desc is empty. I want for the transform to be aborted if the file being loaded is like this one. 

NumberShort DescDesc
111 test1
222 test2
333 test3

 

Appreciate all the help. Thank you.

 

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

@Evren Yamin 

so basically when transform map runs it runs row by row.

You can use onStart transform script and check this

1) query the import set table with the current set

2) check if all records have empty short description

3) if yes then abort the transformation

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hello @Ankur Bawiskar , thanks so much for your response. Do you have a sample script that I can use? I basically need to check all fields on the staging table and not just short description.

 

 

@Evren Yamin 

something like this

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// Add your code here
	var isEmpty = false;
	var gr = new GlideRecord(source.sys_class_name);
	gr.addQuery("sys_import_set", source.sys_import_set);
	gr.query();
	while (gr.next()){
		if(gr.u_short_desription == '' || gr.u_field == ''){
			isEmpty = true;
			break;
		}
	}
	
	if(isEmpty){
		ignore = true;
		log.info("Entire transformation will be ignored");
	}


})(source, map, log, target);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hello @Ankur Bawiskar, does this code mean it will get the current import set?

var gr = new GlideRecord(source.sys_class_name);
gr.addQuery("sys_import_set", source.sys_import_set);