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

Hi Jack,

I've just verified and the email is showing on my request record.

find_real_file.png

Regarding the attachments, check the sys_email_attachment table to see where they ended up.

 

So plot thickens after troubleshooting, I am getting to REQ's being logged, one is the correct one, mapped to the RITM, correct tasks going out but with no attachment, the other is just an REQ with no RITM but the attachment. 

 

Its seems the REQ without the RITM is the "official" record as its referenced in the target record on the inbound email

 

Jack

Jack62
Giga Guru

Hey guys

 

Anyone got any further thoughts? I have tried my own and various scripts from the forums but none seem to actually do every requirement. To confirm all I need is

 

Cat item triggered, with its execution plan included, the attachment added to the ticket and the email details in the activity history. the closest I have got to that is the cat item with execution plan but no attachment and no email info.

 

Thanks

 

Jack

Jack62
Giga Guru

So, with the below script I now have everything working other than the attachment is not on the REQ or the RITM. Any thoughts?

 

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

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);

var item = cart.addItem('4c1398342f302010f2aee36ef699b6f5');

cart.setVariable(item, 'requested_for', 'a2d243d52f202010f2aee36ef699b68e');
cart.setVariable(item, 'request_short_description', email.subject.toString());
cart.setVariable(item, 'request_description', email.body_html);
cart.setVariable(item, 'request_type', 'others');

var rc = cart.placeOrder();

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.contact_type = "email";
ritmRec.update();
}
//update target in email table, as it won't be updated as the record was inserted through cart API
if (rc != '') {
var email_rec = new GlideRecord('sys_email');
email_rec.get(sys_email.sys_id);
email_rec.instance = rc.sys_id;
email_rec.target_table = "sc_request";
email_rec.update();
}
})(current, event, email, logger, classifier);

 

Thanks

 

Jack

Were you able to check sys_email_attachment to see where the attachments of the record were pointing?

If they're remaining on the email record, you can use the GlideSysAttachment copy() function to move the attachments to the REQ / RITM.