How do I create an incident from error logging from an import

Bart Jan Bultma
Kilo Sage

We have an import that runs daily on a file with all existing workstations. In the onBefore transform script an error is logged if a new workstation is found that can't be coalesced to an existing record.

 

After the import I want to have an incident with an overview of the error logs so we can check these workstations manually. How do I do this? I have checked existing business rules and onComplete scripts but I cant find what I am looking for.

12 REPLIES 12

@Bart Jan Bultma 

it depends on your business requirement.

You can create 1 incident and add all the names in short_description or description field and also mention the import set number.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes! This is exactly what I want. I want to have an incident with all the error logs (every workstation found is an error log).
How can I write the full error log of this import into an incident? would this work:

gr.description = log.error();

Hi @Bart Jan Bultma ,

I did something like this before (but triggered from a flow) to check all imports of the previous day on errors.

I used work notes so that I could create direct links to the records, however this would need you to allow the use of [ code ] in your work notes.

If you allow that within ASR, you could use the following. Use the last line before the insert of your incident, to fill the worknotes with the generated content.

var workNote = '[code]Errors have been found for <a href="' + import_set.getLink() + '">' + import_set.getDisplayValue() + '</a></br>';
var count = 0;
var grImportLog = new GlideRecord('import_log');
grImportLog.addQuery("import_set", import_set.getUniqueValue()(
grImportLog.addQuery("level","2");
grImportLog.orderByDesc('sys_created_on');
grImportLog.query();
while (grImportLog.next()) {
    count++;
workNote += '<a href="'+grImportLog.getLink()+'">Error ' + count +'</a></br>';
   }
   workNote += '[/code]';

  incident.work_notes.setJournalEntry(workNote);

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Hi Peter,

Thanks for sharing your solution! Using worknotes is a good idea!

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.