How can I add an email attachment to a request created from an inbound action?

heidiyablonski
Tera Contributor

Hello community,

I have an inbound action that creates a request,ritm and task but I can't get the attachment from the trigger email to attach to the req, ritm or task (like it works for an incident inbound action).

How can I determine why the attachment isn't coming over and/or how can I make the attachment carry over to the req /ritm or task?

I am a n00b -please be kind, all suggestions are greatly appreciated.

Thanks,

Heidi

8 REPLIES 8

createRequest();


function createRequest() {


                            gs.log('Executing......'+email.body.username.toString());


                            //Get Requested For


                            var usr = new GlideRecord('sys_user');


                            usr.addQuery('user_name',email.body.username.toString());


                            usr.addActiveQuery();


                            usr.query();


                            if(usr.next())


                                                          {


                                                          var grRequest = new GlideRecord ("sc_request");


                                                          grRequest.initialize();


                                                          grRequest.requested_for = usr.sys_id;


                                                          grRequest.short_description = email.body.url.toString();


                                                          grRequest.description = "received from: " + email.origemail + "\n\n" + email.body_text;


                                                          var requestSysId = grRequest.insert();




                                                          // Add attachment


                                                          GlideSysAttachment.copy('sys_email',sys_email.sys_id, 'sc_request', requestSysId);




                                                          gs.log('Request Number...'+grRequest.number);


                                                          //Create Request Item


                                                          current.requested_for = usr.sys_id;


                                                          current.short_description = email.body.url.toString();


                                                          current.description = "received from: " + email.origemail + "\n\n" + email.body_text;


                                                          current.cat_item = '5f48751edb58030081d8f9b9af9619ca';


                                                          current.parent = requestSysId;


                                                          current.request = requestSysId;


                                                                                        current.approval = "approved";


                                                          current.insert();


                                                                                        //Create Task


                                                                                        var grTask = new GlideRecord   ("sc_task");


                                                          grTask.initialize();


                                                          grTask.requested_for = usr.sys_id;


                                                          grTask.short_description = email.body.url.toString();


                                                          grTask.description = "received from: " + email.origemail + "\n\n" + email.body_text;


                                                          var taskSysId = grTask.insert();


                                                                                        current.cat_item = '5f48751edb58030081d8f9b9af9619ca';


                                                                                        current.approval = "approved";


                                                          }



}



Thank you for your reply ☺



I just tested it but I'm still not setting the attachment. ☹


Donald Small1
Tera Expert

Were you able to get this to work?  I am running into the same issue with an inbound action to create a request.  Everything is working except the attachment.  Below is my actions script:

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
	
	createRequest();
	
	function createRequest() {
		// Set up variables
		var short_description = email.subject.toString();
		var body = email.body_text.toString();
		var message = "received from: " + email.origemail + "\n\n" + body;
		var cat_item = '1ad2b77b4fed7700cc77d3ef0310c74e'; // Catalog item sys_id AD Objects Cleanup
		var requested_for = '02df27374fed7700cc77d3ef0310c71f'; // User account sys_id ADObjectsCleanup
		
		var cart = new sn_sc.CartJS();
		var item =
		{
			'sysparm_id': cat_item,
			'sysparm_quantity': '1',
			'variables': {
				'notes': message
			}
		};
		cart.addToCart(item);
		
		var request =
		{
			'special_instructions' : '',
			'requested_for' : requested_for,
			'delivery_address' : '',
		};
		
		// Place order from cart
		var requestDetails = cart.submitOrder(request);
		
		// Update details in the Requested Item
		// Pull out the Request Sys ID from the order
		var reqSysID = requestDetails.request_id;
		
		// Update the RITM to have a short description from the email
		var rec = new GlideRecord('sc_req_item');
		rec.addQuery('request', reqSysID);
		rec.query();
		// Check for a record
		if (rec.next()) {
			// Get the RITM, should be the only item with this parent
			rec.short_description = short_description;
			rec.comments = message;
			rec.update();
		}
	}
	
})(current, event, email, logger, classifier);

yed
Tera Contributor

Hi all,

 

Any luck on this ? i have a similar scenario.

 

Thanks