- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2016 06:49 AM
I have an import set/data source that is created when a users sends a file into ServiceNow with a specific subject and then transformed. It will then trigger 5 transform maps to load all the data into the correct tables.
After the transform is complete and the import set has finished being processed, I would like to gather all the errors to be sent to a user by email. I've done this before with an onComplete script that creates an event which then triggers an email. I am trying to use a Business Rule so I can gather all the errors for each of the 5 transform maps instead of writing 5 different onComplete scripts.
My Business Rule isnt running correctly and the GlideRecord queries are not returning anything. Current.sys_id (the import set sys id) isnt working for the GlideRecord lookup but if I log it I can see the value in the script log. It will work if I hardcode a sys_id and it will also work if I reprocess the import set manually but it fails if I send the data via an email to process.
(function executeRule(current, previous /*null when async*/) {
gs.log('Import set email error BR running, sys_id is: ' + current.sys_id);
//Query the import set row table to get with the sys_id of the import set and remove rows where the error is null
var setRow = new GlideRecord('sys_import_set_row');
setRow.addQuery('sys_import_set', current.sys_id);
setRow.addNotNullQuery('sys_row_error');
setRow.query();
while(setRow.next()){
//Add one to the row number so it will correspond to the row in the excel sheet
var rowNum = setRow.sys_import_row++;
//Get the error message using the sys_id of the error message on the import set row table
var error = getErrorMessage(setRow.sys_row_error);
gs.log('Row: ' + rowNum + ' Error Found: ' + error);
}
function getErrorMessage(sys_id) {
var errorMessage = new GlideRecord('sys_import_set_row_error');
errorMessage.get(sys_id);
errorMessage.query();
return errorMessage.error_message;
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2016 08:48 AM
Hi Steve,
I don't consider that to be an issue as you can access import set sys id using import_set as that would remain the same irrespective of transform maps.
- var setRow = new GlideRecord('sys_import_set_row');
- setRow.addQuery('sys_import_set', import_set.sys_id); // alternatively you can use import_set
- setRow.addNotNullQuery('sys_row_error');
- setRow.query();
- while(setRow.next()){
- //Add one to the row number so it will correspond to the row in the excel sheet
- var rowNum = setRow.sys_import_row++;
- //Get the error message using the sys_id of the error message on the import set row table
- var error = getErrorMessage(setRow.sys_row_error);
- gs.log('Row: ' + rowNum + ' Error Found: ' + error);
- }
- function getErrorMessage(sys_id) {
- var errorMessage = new GlideRecord('sys_import_set_row_error');
- errorMessage.get(sys_id);
- errorMessage.query();
- return errorMessage.error_message;
- }
More detail on oncomplete script
http://wiki.servicenow.com/?title=Transform_Map_Scripts#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2016 08:48 AM
Hi Steve,
I don't consider that to be an issue as you can access import set sys id using import_set as that would remain the same irrespective of transform maps.
- var setRow = new GlideRecord('sys_import_set_row');
- setRow.addQuery('sys_import_set', import_set.sys_id); // alternatively you can use import_set
- setRow.addNotNullQuery('sys_row_error');
- setRow.query();
- while(setRow.next()){
- //Add one to the row number so it will correspond to the row in the excel sheet
- var rowNum = setRow.sys_import_row++;
- //Get the error message using the sys_id of the error message on the import set row table
- var error = getErrorMessage(setRow.sys_row_error);
- gs.log('Row: ' + rowNum + ' Error Found: ' + error);
- }
- function getErrorMessage(sys_id) {
- var errorMessage = new GlideRecord('sys_import_set_row_error');
- errorMessage.get(sys_id);
- errorMessage.query();
- return errorMessage.error_message;
- }
More detail on oncomplete script
http://wiki.servicenow.com/?title=Transform_Map_Scripts#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2016 09:08 AM
Awesome I think I glanced over the import_set variable when I was looking.
Let me do some more testing but it looks like everything is working now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2024 09:12 PM
Hi @venkatiyer1 ,
How we create an email notification and add link of the actual ignored records.
Or can we create a hyperlink such that when user clicks on it in email notification then the excel of the ignored records will get exported.
thanks in advance