How to set the target field in Email logs with Request/RITM number,when request is created through inbound email action

robinpaul
Kilo Contributor

Hello All,

I have created an inbound email action to Create a Request and Requested Item in Catalog when an email is received into servicenow. I have set Target Table as: Shopping Cart(sc_cart)

The Script work well and it creates a Request and Request Item. But my When i see the email logs from   System Logs-->Emails and open the received email. Here the Target field is populating as "Shopping Cart: DEFAULT"

My Question is, Is there a way that i can populate the target field with RITM Number in the email log.

inbound email action script :

createRequest();  

function createRequest() {      

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

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

 

  cart.setVariable(item, 'request_short_description', email.subject.toString());  

  cart.setVariable(item, 'request_description', email.body_html);  

  cart.setVariable(item, 'short_title', email.subject.toString());  

  cart.setVariable(item, 'screen_wipes','1');  

  cart.setVariable(item, 'copier_reams','1' );  

  // set the requested for  

  var gr = new GlideRecord("sys_user");  

  gr.addQuery("email", email.from);  

  gr.query();  

  if (gr.next()) {  

  var cartcartGR = cart.getCart();  

  cartGR.requested_for = gr.sys_id;  

  cartGR.update();  

  }  

    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.short_description = email.subject;  

    ritm.update();      

       

  }      

}  

// current.setAbortAction(true);  

event.state="stop_processing";  

Any Pointers would be helpful ! Thanks in advance for any assistance.

Message was edited by: Robin paul

8 REPLIES 8

robinpaul
Kilo Contributor

Please Need Help...


Hi Robin, I'm running into the same issue.. were you able to get this resolved?



Edit: I was able to get this updated using the following glideRecord:



var emailGR = new GlideRecord("sys_email");


emailGR.addQuery("sys_id", sys_email.sys_id);


emailGR.query();


if(emailGR.next()){


  emailGR.instance = incSysID;


  emailGR.target_table = "incident";


  emailGR.update();


}



Hope this helps!


dedeepyatirugu
Tera Contributor

Hello Robin,



If you get the solution, please post it here. We have the same requirement.



Thanks In advance.



Regards,


Dedeepya


kuba4
Kilo Expert

Hi Robin,

 

Did you manage to resolve the issue?

I have similar problem.