Check If import set is completed successfully or not through workflow

Vishwa Pandya
Tera Expert

Hello,

I have a workflow which is triggered when a user wants to bulk upload a list of Hardware Assets or Hardware Models.

I have defined Data source, Scheduled Import Set and Transform Map for the same.

Now what I want to do is to check at the end of the workflow whether the Import Set was completed Successfully or not. If completed successfully I want to close the RITM and the REQ and if not competed or completed with errors then I want to assign the RITM to service desk.

(basically something that cross checks the records in the excel sheet provided by the user and the records uploaded in the target table)

Please let me know how this can be achieved.

1 ACCEPTED SOLUTION

chrisperry
Giga Sage

Hi there,

You will need to query the Transform History (sys_import_set_run) table and check the State for the import/transform that you just triggered. If the State is Complete then close out the RITM/REQ, if the State is something else (for ex: Complete with errors), then reassign RITM to the service desk.

The trick is going to be how do you determine which sys_import_set_run record is the one that was triggered from this specific workflow vs. some other process, but for simplicity sake you could always set up your query like below (be sure to update the addEncodedQuery line of code with your import set table name accordingly):

var successfulImport = false;
var transformGr = new GlideRecord('sys_import_set_run');
transformGr.addEncodedQuery('set.table_name=import_set_table_name_here'); //be sure to replace w/ your import set table name
transformGr.orderByDesc('sys_created_on');
transformGr.setLimit(1);
transformGr.query();
if (transformGr.next()) {
       successfulImport = transformGr.getValue('state') == 'complete' ? true : successfulImport; //if Transform History has State = Complete, then successfulImport variable = true, otherwise it is = false... then use this value to make your decision about what to do with the RITM
}

So basically if Transform History has State = Complete, then the successfulImport variable = true, otherwise it is = false... then use this successfulImport value to make your decision about what to do with the RITM.

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

View solution in original post

2 REPLIES 2

chrisperry
Giga Sage

Hi there,

You will need to query the Transform History (sys_import_set_run) table and check the State for the import/transform that you just triggered. If the State is Complete then close out the RITM/REQ, if the State is something else (for ex: Complete with errors), then reassign RITM to the service desk.

The trick is going to be how do you determine which sys_import_set_run record is the one that was triggered from this specific workflow vs. some other process, but for simplicity sake you could always set up your query like below (be sure to update the addEncodedQuery line of code with your import set table name accordingly):

var successfulImport = false;
var transformGr = new GlideRecord('sys_import_set_run');
transformGr.addEncodedQuery('set.table_name=import_set_table_name_here'); //be sure to replace w/ your import set table name
transformGr.orderByDesc('sys_created_on');
transformGr.setLimit(1);
transformGr.query();
if (transformGr.next()) {
       successfulImport = transformGr.getValue('state') == 'complete' ? true : successfulImport; //if Transform History has State = Complete, then successfulImport variable = true, otherwise it is = false... then use this value to make your decision about what to do with the RITM
}

So basically if Transform History has State = Complete, then the successfulImport variable = true, otherwise it is = false... then use this successfulImport value to make your decision about what to do with the RITM.

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

Appreciate the help! Was stuck on this since 2 days!