Script to check if table exists

Monish2
Tera Contributor

Hi, I am creating a scoped application for integration and have few transform maps. I want to run a transform map only if the target table exists. can we do that through scripting? thanks in advance!

1 ACCEPTED SOLUTION

Hi,

Glad to know that it worked.

Please use onStart transform script so that entire transformation is skipped if table not found

Also you should use ! operator in the gs.tableExists('table_name')

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

	// Add your code here
	if(!gs.tableExists('table_name')) {
		ignore = true;
		log.info('Table not found so entire transformation is skipped');
	}

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

Regards
Ankur

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

View solution in original post

12 REPLIES 12

I didn't change the Accessible from for that Script Include.

Directly used this

gs.tableExists('incident')

Are you able to use the above single line

Regards
Ankur

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

 this works! sorry, I had some typo i guess.

so my script for onbefore transform is 

if (gs.tableExists('table_name')) {
    ignore = true;
}

 

still the transform map is failing. is there something I am missing?

 

Thank you so much again. you are saving my time.

Hi,

Glad to know that it worked.

Please use onStart transform script so that entire transformation is skipped if table not found

Also you should use ! operator in the gs.tableExists('table_name')

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

	// Add your code here
	if(!gs.tableExists('table_name')) {
		ignore = true;
		log.info('Table not found so entire transformation is skipped');
	}

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

Regards
Ankur

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