The CreatorCon Call for Content is officially open! Get started here.

Setting Short Description using Inbound Email with Cart API

gaf627
Tera Expert

I'm receiving email from HR system and using Inbound Email Action with Cart API for Associate Onboarding.   It works perfectly; however, I'm unable to change the short description.   I would like to set the short description = to the email subject (Associate On Boarding, John Doe).   I'm using the email and script below.   But, it keeps defaulting to the short description on the Catalog Item.     I've also tried using the Field actions, but this results in the creation of a second RITM.   Any help would be appreciated.   Thanks!

find_real_file.png

find_real_file.png

4 REPLIES 4

Mwatkins
ServiceNow Employee
ServiceNow Employee

The short_description field of an sc_req_item record is set in the proprietary code. You could write an after/create Business Rule to change the value after the fact using the value that comes through in your variable. This would be a departure from the standard method of doing things obviously, but I'm sure you've considered that. Normally each requested item short description refers to the generic catalog item that was requested but I don't see any intrinsic reason it couldn't be more specific. Good luck!


Abhinay Erra
Giga Sage

Hi gaf627



    Add this code after the line var rc=cart.placeOrder();


var gr= new GlideRecord('sc_req_item');


  gr.addQuery('request',rc.sys_id);


  gr.query();


  while(gr.next()){


  gr.short_description=email.subject;


  gr.update();


  }


Hi Abhinay,



I added your code, which resulted two RITMs with same record number being added to the request.   The 2nd one has the short description.   This gets me closer, but creates a larger issue by having RITMs with the same record number.



createRequest();
function createRequest() {
var cart = new Cart();
// add in cart, substitute your cat item sys_id
var item = cart.addItem('c6b40cc86f262200739d841dba3ee4ba');


//Look up the user table for someone with the same name.
var user = new GlideRecord('sys_user');
if(user.get('email', email.body.supervisoremail))
{
//Found the users with a matching name,
cart.setVariable(item, 'requested_for', user.sys_id);
}
else
{
//No matching user
cart.setVariable(item, 'requested_for', '67cb84cc6f262200739d841dba3ee424');
}

//Set Variables in your Cart Item

var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
cart.setVariable(item,'comments',cartmsg);
var rc = cart.placeOrder();
 
var gr= new GlideRecord('sc_req_item');

    gr.addQuery('request',rc.sys_id);
    gr.query();
    while(gr.next())
    gr.short_description=email.subject;
    gr.update();
 
}


Abhinay Erra
Giga Sage

It worked for me on my instance. It only updated the existing ritms