Below script in nor working correctly

keval3
Tera Contributor

Hi All,

I have written below inbound email action script on sc_req_item table

by using that 2 request are created 1 with proper catalog item and another one in without catalog item please let me know what is issue in my script.

keval3_0-1730913502603.png

var cart = new Cart();
    // // add in cart, substitute your catalog item sys_id
    var item = cart.addItem('49dd78a3db427c50eeb8026dd3961902');
     cart.setVariable(item, 'description', email.body);
     cart.setVariable(item, 'contact_type', 'email');
     cart.setVariable(item, 'requested_for', '3336eb92dba9dc10a73ddf0bd39619bd');
    cart.setVariable(item, 'subject', email.subject);
    var rc = cart.placeOrder();

  Thanks & Regards

KP

 

7 REPLIES 7

Hi @keval3 ,

 

Use only one time to generate the RITM. Use below code exactly.

You can run this in background script as well, just to check that it create only one RITM.

Let me know if still face any issue.

var id = GlideGuid.generate(null); 
    var cart = new Cart(id); 
    var item = cart.addItem('49dd78a3db427c50eeb8026dd3961902');
    cart.setVariable(item, 'contact_type', 'email');
    cart.setVariable(item, 'sub_heads', 'nurture_business');
    var request = cart.placeOrder();

 

And make sure your inbound action is executing only one time.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Hi Ranjay,

I have used same code now still 2 tickets created. 1 with items and another one is blank.

keval3_0-1730962523908.png

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

    // Implement email action here

   var id = GlideGuid.generate(null);
    var cart = new Cart(id);
    var item = cart.addItem('49dd78a3db427c50eeb8026dd3961902');
    cart.setVariable(item, 'contact_type', 'email');
    cart.setVariable(item, 'sub_heads', 'nurture_business');
    var request = cart.placeOrder();

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

 

Hi Ranjay,

 

I have tried same code in test instance in that blank tickets are created. items are not getting populated. please help me resolved my issue. kindly find below screen snap.

keval3_0-1730973362077.png

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

    // Implement email action here
    var id = GlideGuid.generate(null);
    var cart = new Cart(id);
    var item = cart.addItem('49dd78a3db427c50eeb8026dd3961902');
    cart.setVariable(item, 'contact_type', 'email');
    cart.setVariable(item, 'sub_heads', 'nurture_business');
    var request = cart.placeOrder();

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