- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 10:25 AM
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.
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2020 07:31 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2020 01:26 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2020 02:00 PM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2020 02:39 PM
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2020 03:23 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2020 07:31 AM
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