Automatic incident creation from transform map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 11:42 AM
Hi All,
I have one JDBC data source. I need to create incident automatically when imported data count is 0 or import set job is completed with error or cancelled or did not complete. I have written below transform map script on complete .Could you please help me here what i am doing wrong here.Thanks in Advance
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var grImp = new GlideRecord('sys_import_set_run');
grImp.addQuery('set',import_set.sys_id);
grImp.query();
if (grImp.state == 'cancelled' || grImp.state == 'complete_with_errors'|| grImp.total ===0) {
var grInc = new GlideRecord('incident');
grInc.initialize();
grInc.short_description = 'Review the import set ' +
import_set.number + 'and troubleshoot if it is canceled/completed with errors or imported data count is less than 0';
grInc.assignment_group = '86f9bb4d1bec8c10532d6288bd4bcb97';
grInc.description = import_set.number;
grInc.insert();
}
})(source, map, log, target);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 08:49 PM - edited 07-22-2024 09:07 PM
Hi @_bhishek ,
Where is "import_set.sys_id" defined?? are you quering before this script if not please do
Ex:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var grImp = new GlideRecord('sys_import_set_run');
grImp.addEncodedQuery('set.table_name=import_set_table_name_here'); //replace your import set table name
grImp.orderByDesc('sys_created_on');
grImp.setLimit(1);
grImp.query();
if(grImp.next()){
if (grImp.state == 'cancelled' || grImp.state == 'complete_with_errors'|| grImp.total ===0) {
var grInc = new GlideRecord('incident');
grInc.initialize();
grInc.short_description = 'Review the import set ' +
import_set.number + 'and troubleshoot if it is canceled/completed with errors or imported data count is less than 0';
grInc.assignment_group = '86f9bb4d1bec8c10532d6288bd4bcb97';
grInc.description = grImp.number; //you can use set number like grImp.getDispplayValue(set);
grInc.insert();
}
}
})(source, map, log, target);
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 02:40 AM
Hello Hemanth,
Thanks for your response.
Import_set is API for import sets .Is Import_set.sys_id not correct method to query the sys id of import set and Set Sys ID of import set run .(Import set run table is related table for each import set).Please let me know .
Thanks & regards,
Abhishek

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 03:32 AM
Hi @_bhishek ,
can you try logging import_set.sys_id and see what you get
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025