Automatic incident creation from transform map

_bhishek
Tera Guru

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);

 

3 REPLIES 3

Hemanth M1
Giga Sage
Giga Sage

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);

 

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

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

 

Hi @_bhishek ,

 

can you try logging import_set.sys_id and see what you get

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025