inbound action

Jack62
Giga Guru

Evening all,

I am working on an inbound action which is behaving rather odd. it is meant to fire a specific cat item, log as the person emailing in and take the subject and body as short description and description. At the moment the inbound action states it is being skipped but a the request again the ritm is being generated, logging as the person sending in the email, the short description is not mapping but description IS the body of the email

 

Any thoughts on why the inbound action is stating it skipped when it logged? the error on the email logs is 

create cat request : did not create or update sc_request using current

 

My inbound action script is below

 

 

createRequest();

function createRequest() {

var cart = new Cart(); //calling the cart API

var item = cart.addItem('4c1398342f302010f2aee36ef699b6f5'); //sys_id of the catalog item I want to fire

cart.setVariable(item, 'subject', email.subject); //sets catalog variable to the email's subject

cart.setVariable(item, 'emailbody', email.body_html); //sets catalog variable to email's body

var rc = cart.placeOrder(); //this launches the catalog item, and creates a request object. rc = the request object

updateRITM(rc.sys_id); //call a function immediately to update the ritm. This must be a nested function, otherwise inbound actions get weird.

//also, we're passing the sys_id of the request so we know what RITM to grab.

}

function updateRITM(req){

var ritm = new GlideRecord('sc_req_item');

ritm.addQuery('request', req); //req is what we passed from the previous function. the sys_id of the request.

ritm.query();

while (ritm.next()){

ritm.u_customer = gs.getUserID(); //my ritm table separately tracks its own customer, since I don't use Request

ritm.description = email.body_text; //we're still in the inbound action so why not exploit?

ritm.priority = email.body.priority; //good example of how to exploit email body variables

ritm.update();

}

}

event.state="stop_processing"; //stop evaluating inbound actions. This is why I keep this record's order lower than my incident from email rules.

1 ACCEPTED SOLUTION

Thanks for all the help Kieran

 

This is working end to end in my PDI. I have moved the update set in the proper dev instance and its no longer working. The  cat item and inbound action has come in, I have checked the sys ids that are in the inbound action script and checked all other conditions, the inbound email It gives me the same message against the UI Action as in my instance 

 

my-inbound - action - name : did not create or update sc_request using current

 

In the PDI instance it logs the req with the req_item but in dev it does nothing. 

 

Is there a setting, property etc that I need to look at? I have created the inbound action and cat item from scratch (And update the sys Ids) but still the same response

 

JAck

View solution in original post

15 REPLIES 15

Hey Kieran 

screenshot below of the attachment on the sys_email_attachment table. 

 

find_real_file.png

 

I have tried a few scripts to copy it through on my inbound script but none are firing, could you confirm what the script should look like?

 

Jack

 

 

Thanks Jack,

I've created this function to move the attachments. 

 

function moveAttachments(sys_email, table_name, table_id){
	var target_table = table_name || sys_email.target_table;
	var target_id = table_id || sys_email.instance;

	var attGR = new GlideRecord('sys_email_attachment');
	attGR.addQuery('email', sys_email.sys_id);
	attGR.query();
	
	while(attGR.next()){
		var attachment = attGR.attachment.getRefRecord();
		attachment.table_name = target_table;
		attachment.table_sys_id = target_id;
		attachment.update();
	
		attGR.action = 'attached_to_target_record';
		attGR.action_reason = 'Attachment moved to target via ui action';
		attGR.update();
	}
}

You call it within your self-invoking function using moveAttachments(sys_email). If you want it to go to a different table (i.e the RITM) you would use moveAttachments(sys_email, table_var, sys_id_var);

 

Full example of my test inbound action:

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

	try{
		var cart = new sn_sc.CartJS();
		var item = {
			'sysparm_id': '1dc3e6912f3c20101c43bed72799b67d',
			'sysparm_quantity': '1',
			'variables': {
				'email_body': email.body_text
			}
		};

		var cartDetails = cart.orderNow(item);
		logger.log(JSON.stringify(cartDetails));
	} catch (e){
		logger.logWarning(e);
	}
	sys_email.target_table = cartDetails.table;
	sys_email.instance = cartDetails.request_id;

	moveAttachments(sys_email);

})(current, event, email, logger, classifier);

function moveAttachments(sys_email, table_name, table_id){
	var target_table = table_name || sys_email.target_table;
	var target_id = table_id || sys_email.instance;

	var attGR = new GlideRecord('sys_email_attachment');
	attGR.addQuery('email', sys_email.sys_id);
	attGR.query();
	
	while(attGR.next()){
		var attachment = attGR.attachment.getRefRecord();
		attachment.table_name = target_table;
		attachment.table_sys_id = target_id;
		attachment.update();
	
		attGR.action = 'attached_to_target_record';
		attGR.action_reason = 'Attachment moved to target via ui action';
		attGR.update();
	}
}

Jack62
Giga Guru

You are a gent! That has the cat item firing and the attachment is now on the REQ, is there a way of getting the attachment on the RITM?

 

And final question (I promise) in my previous versions we have mapped short description and description to bring in the email subject and body using the below, how do I do this in your version?

 

var ritmRec = new GlideRecord("sc_req_item");
ritmRec.addQuery("request", rc.sys_id);
ritmRec.query();
if (ritmRec.next()) {
ritmRec.short_description = email.subject.toString();
ritmRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
ritmRec.description = email.origemail + "\n\n" + email.body_text;
ritmRec.contact_type = "email";
ritmRec.update();

 

Many thanks once again!

To move it to the RITM, just need to GlideRecord to it:

var ritms = new GlideRecord('sc_req_item');
	ritms.addQuery('request', cartDetails.request_id);
	ritms.query();
	if(ritms.next()){
		
		moveAttachments(logger, sys_email, ritms.getTableName(), ritms.getUniqueValue());
		
	}

You can also add in your bits to update values on the RITM record:

var ritms = new GlideRecord('sc_req_item');
	ritms.addQuery('request', cartDetails.request_id);
	ritms.query();
	if(ritms.next()){
		
		moveAttachments(logger, sys_email, ritms.getTableName(), ritms.getUniqueValue());
		
		ritms.short_description = email.subject
		ritms.description = email.body_text
		ritms.update();
	}

Thanks for all the help Kieran

 

This is working end to end in my PDI. I have moved the update set in the proper dev instance and its no longer working. The  cat item and inbound action has come in, I have checked the sys ids that are in the inbound action script and checked all other conditions, the inbound email It gives me the same message against the UI Action as in my instance 

 

my-inbound - action - name : did not create or update sc_request using current

 

In the PDI instance it logs the req with the req_item but in dev it does nothing. 

 

Is there a setting, property etc that I need to look at? I have created the inbound action and cat item from scratch (And update the sys Ids) but still the same response

 

JAck