- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2021 07:20 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2021 06:44 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2021 07:22 AM
Hi there,
You might use TableUtils tableExists()
Example code:
var table = new TableUtils("my_table");
gs.print("Does 'my_table' exist? " + table.tableExists());
Or if scoped:
var table = new global.TableUtils("my_table");
gs.print("Does 'my_table' exist? " + table.tableExists());
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2021 07:35 AM
Hi,
Mark has already mentioned the script include and function name
If your transform map is in scoped application and you want to check in that then you need to use the global prefix for that script include
var table = new global.TableUtils("incident");
gs.info("Does 'my_table' exist? " + table.tableExists());
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2021 08:15 AM
Thanks for the response Ankur. Let me give some more specifics of my use case.
I want to check if the target table exists on the instance, if it does, perform the transform map else ignore so that there are no errors in transform history.
I did use the script you shared but it fails with null pointer error.
also, since the scope of the app is custom, will global scope script work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2021 08:29 AM
Hi,
but you must be having defined target table in the transform map right then why to check if table exists?
You are loading data to which table?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader