Create Service Request from Inbound EMail - File attachment missing

Duaine Johnson1
Giga Expert

I have what should be a simple requirement to implement - Detect an inbound email with a specific subject and create a service request.

All other inbound email actions have an 'Order' of 100, the one I have created is set to 90 and ends with: event.state="stop_processing";

Full code on the Inbound Email Action is as follows:

=================================

// Create the top level / parent REQ ticket

var grREQ = new GlideRecord('sc_request');

grREQ.short_description = "Dynamics AX Security Audit Review";

// Create the child RITM ticket

var grRITM = new GlideRecord('sc_req_item');

grRITM.request = grREQ.insert();

grRITM.short_description = "Dynamics AX Security Audit Review";

grRITM.cat_item='4d496271db102200bcbed540cf9619ca';

grRITM.requested_for='72d53761db102200bcbed540cf961919';

grRITM.state=0;

var RITM_sysID = grRITM.insert();

//Trigger the workflow to begin (otherwise no WF will be attached to the RITM unless it is manually updated)

grRITM.state=1;

grRITM.update();

// current.short_description += "."

// current.update();

event.state="stop_processing";

=========================================

With the code above, exactly as-is, everything works but the file attachment that is part of the original email is not part of the REQ/RITM tickets.

Interestingly enough, to me anyways, the commented lines near the bottom (current.*) were the original code provided to me by someone to trigger the workflow.   All this seemed to do was create an Incident ticket with the file attachment I needed.   When these were commented out and the event.state line was also commented out, the incident ticket was still created, but without the file attachment in question.

The file attachment that I'm testing with is a 12KB Word document, eventually the actual audit reports that will be included in the incoming emails will be PDF files, but should remain well under 1MB.

So, long story short, I need to ensure file attachments included on the inbound email are included in the service request that is created with this inbound email action.

This is all being done in my developer instance at the moment as this is my first foray into ServiceNow development.   Both my instance and the corporate instance I will be implementing this into are running Fuji.

As a n00b, I do apologize if this is agonizingly easy.. and I'm sure I'll have the light-bulb moment as soon as the answer is presented.   That said, thank you in advance for your time and most of all.. patience.

Duaine.

1 ACCEPTED SOLUTION

Duaine Johnson1
Giga Expert

With a little help from Param's suggestion, I've found my answer through some more trials and tribulations.   I'll try to explain it out as best I can for anyone who might read this in the future.



When setting up your inbound email action to include file attachments, decide where you want those attachments to go (in my case REQ or RITM ticket - I chose RITM in the end as it better suits my organization's needs at this point.



As Param mentioned above, the variable 'current' is automatically defined as a record destined for the 'Target table' you set.   All of your information after that can be defined using current.* = *value*   (example, your RITM will have the short description of "Dynamics AX".. simply use: current.short_description = "Dynamics AX"; instead of going the long way round (like I did) of creating the RITM record, assigning the variables and then updating the record - This may work, but it will fail to include file attachments!)



Create a parent (REQ) ticket, then use 'current' to create the RITM ticket, set the variables you need prior to inserting, including a base state (current.state=0; below) that you will update momentarily.



Insert the 'current' record (creates the RITM, attaches to REQ if you define the 'current.request' value as the sysID of the Request (reqSysID = grREQ.insert(); on line 4)



Everything else should be fairly straight-forward.   I found it a bit tricky to dig up the SysID for the work flow I needed, but everything else fell into place once I was able to follow the logic of the 'current' variable and how to use it.



Finally, update the current.state to an appropriate value in your environment and update();   This will attach/kick off the work flow for your RITM.   I did see another way to do this posted in a couple of places, but I found this to be suitable for my needs in two simple lines.



Thanks to those who helped and pointed me in the right direction.   I have no doubt that I'll be back at some point when I am tasked with something else I've never done before.



One final note: Use "Reprocess Email" with caution, I have found that it does NOT include the original file attachments.   Use it to test and re-test everything else, but the file attachments (I found) will have to be processed from newly received emails.



My successful code is as follows:



// Create the 'parent' REQ record.


var grREQ = new GlideRecord('sc_request');


grREQ.short_description = "Dynamics AX Security Audit Review";


var reqSysID = grREQ.insert();



// 'current' = RITM record, update variables and insert.   This will include file attachments from original email


current.short_description = "Dynamics AX Security Audit Review";


current.cat_item='4d496271db102200bcbed540cf9619ca';


current.request=reqSysID;


current.requested_for='72d53761db102200bcbed540cf961919';


current.state=0;



current.insert();



// Update state, this kicks off the work flow.   Without this, no WF will be attached until RITM is manually updated.


current.state=1;


current.update();



// Stop further processing of inbound emails.


event.state="stop_processing";


View solution in original post

13 REPLIES 13

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Duaine,



You may find below thread helpful.


Re: Missing attachments for incoming emails in Servicenow


Thanks Pradeep,



I did see that thread prior to posting and the questions posed don't appear to apply to the roadblock I'm facing.



See my note back to Param below for more.. it seems the attachments only make their way into a ticket if I use the 'current' insert rather than the glide record insert, but each time I use 'current', it creates an Incident instead of a Request.



Duaine.


Ashutosh Munot1
Kilo Patron
Kilo Patron

So you want attachment in the inbound email to be attached to ticket


Correct, the attachment on the inbound email needs to be attached to the REQ ticket that is created using the code above.