Relating a scheduled import to an RITM

Patrick Steele
Tera Contributor

Greetings,

 

I have created a process to automate the import of data import from user submitted excel files, very similar to the following posts:

https://www.servicenow.com/community/developer-blog/automate-data-import-from-excel-file-attachment-...

https://www.servicenow.com/community/developer-blog/data-load-and-transform-via-catalog-item/bc-p/25...

The main difference being that I have done this in Flow Designer instead, but it works perfectly.

 

My only issue is that I need a way to be able to relate the specific import to the RITM created when the user submits the catalog item and excel file. The reason for this is that we have had rare cases where something went wrong either because of a user error or because the attachment didn't copy before the execution of the scheduled import. But I cannot for the life of me figure out a way to do this. I have considered that I could update the attachment record and rename the file name to the RITM but because I am using a scheduled import with a data set it does not use the file name as it would if I manually loaded them. I am even fine with adding an RITM field if needed I am just not entirely sure how I would set the value.

 

To summarize. The process is as follows:

 

User submits catalog item with excel document > catalog flow starts and copies the attachment to the data source via the standard copy attachment action > custom action containing the following script is executed:

	var exportGr = new GlideRecord("scheduled_import_set");
	exportGr.addQuery("sys_id", inputs.import_sys_id);
	exportGr.query();
	if (exportGr.next()) {
		gs.executeNow(exportGr);
	}  

 

Then the scheduled import deletes the document from the data source and the process is complete. This all works swimmingly. But we simply want to be able to create a PTSK for ourselves in the event that something is not submitted properly or there is a rare error, ideally inside the catalog item flow.


Any ideas would be appreciated.

3 REPLIES 3

Joe S1
Kilo Sage

Hello @Patrick Steele 

 

You're only going to want a TASK if there is possibly an issue. So, in your Flow put a wait in (i.e. 5 minutes) after the import is triggered. Then do a GlideRecord lookup for the import set and if (Total records = 0 or if Errors is greater than 0), which would indicate a possible problem, and from there generate a TASK record.

How can I find the right import set though? That is what I am not sure about. As far as I am aware when executing this via scripting there is no way to grab the specific import set.

You could do a lookup against the sys_import_set table for any import sets created in the last 5 minutes for your specific import set table (table_name) that you're using for this import process. What's the likelihood that there would be multiple import sets created within that time period?