how to Load data from an email attachment and create an incident and associate the new incident record with loaded data

____39
Tera Contributor

I want to load data via email attachment, and create an incident at the same time while loading data, but how to associate the new incident record with loaded data?  Thank you!

2 ACCEPTED SOLUTIONS

Hi,

can you print what came in source.sys_import_set.number?

try this

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    var gr = new GlideRecord("incident");
    gr.initialize();
    gr.short_description = import_set.number;
    gr.insert();

})(source, map, log, target);

Similarly update the onAfter

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    var gr = new GlideRecord("incident");
    gr.addQuery("short_description", "LIKE", import_set.number);
    gr.query();
    if (gr.next()) {
        target.fieldName = gr.getUniqueValue(); // if target field is reference to incident

        // OR

        // target.fieldName = gr.number; // if target field is string
    }

})(source, map, log, target);

Regards
Ankur

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

View solution in original post

Please mark my response as correct and close the thread.

Regards
Ankur

 

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

View solution in original post

18 REPLIES 18

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

for the 1st part you can refer this link

Auto load Excel spreadsheet using Email Inbound Action

For the 2nd part linking that incident to all the loaded records you can do this

1) create incident first with specific short description which can be used to easily identify the incident created from inbound action

2) in the transform map onAfter script; query incident table and search for this specific incident and update the target field

Regards
Ankur

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

Hi , Ankur , Thank you for answering! For the 2nd part linking that incident to all the loaded records, Can you tell me exactly how to write the script?  Thank you!

1) create incident first with specific short description which can be used to easily identify the incident created from inbound action

2) in the transform map onAfter script; query incident table and search for this specific incident and update the target field

Hi there,

 

Use the below onAfter script.

var gr = new GlideRecord('incident');
gr.get(target.sys_id);
gr.setValue('<field_name>', <value>);
gr.update();

 

replace the <field_name> with the target field that you want to update.

 

Regards,

Snehangshu Sarkar

 

Hi ,thank you for answering,I think incident should be created from inbound action,onAfter script should update target field with created incident's sysId, but how to find the new created incident?