Inbound action to create REQUESTS

Saloni Suthar
Mega Sage
Mega Sage

Hello everyone,

I am trying to create a REQ/RITM through the inbound action but the script is acting weird. 

Table : sc_req_item.

Script:

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

createRequest();


function createRequest() {
var cart = new Cart();
// add in cart, substitute your cat item sys_id
var item = cart.addItem('81fc44c9978d45109ebbfaf3a253afc7');
cart.setVariable(item, 'description', email.body.comments);

var rc = cart.placeOrder();
var ritm_id = rc.sys_id;
rc.opened_by = current.email.recipients;
rc.requested_for = email.recipients;
rc.update();

attachments(ritm_id);

}

function attachments(ritmID) {
var emailRec = new GlideRecord("sys_email");
emailRec.addQuery("uid", email.uid);
emailRec.orderByDesc("sys_created_on");
emailRec.query();
if (emailRec.next()) {
GlideSysAttachment.copy("sys_email", emailRec.sys_id, "sc_req_item", ritmID);
emailRec.instance = ritmID;
emailRec.target_table = 'sc_req_item';
emailRec.update();

}

}

 


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

 

Email is getting processed and RITM gets created but it creates two RITMS. One RITM gets attached to the REQ and follows the workflow but the other one doesn't. 

find_real_file.png

I have also tried https://community.servicenow.com/community?id=community_blog&sys_id=c25da629dbd0dbc01dcaf3231f961933&feedbackAction=comment but it is acting the same.

 

Any leads would be greatly appreciated.

Thank you!


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni
1 ACCEPTED SOLUTION

GoBucks
Mega Sage

Hi saloni,

I am guessing the inbound action is creating 2 RITM records because the inbound action inherently creates a record in the table you have defined (sc_req_item), and then the inbound action's script just so happens to be using the Service Catalog Script API and that is creating the second RITM on its own.

Have you tried using the following in your script?

current.setAbortAction(true);

https://developer.servicenow.com/dev.do#!/reference/api/rome/server_legacy/c_GlideRecordAPI#r_GlideR...

 

Please mark correct if that answered your question.

View solution in original post

1 REPLY 1

GoBucks
Mega Sage

Hi saloni,

I am guessing the inbound action is creating 2 RITM records because the inbound action inherently creates a record in the table you have defined (sc_req_item), and then the inbound action's script just so happens to be using the Service Catalog Script API and that is creating the second RITM on its own.

Have you tried using the following in your script?

current.setAbortAction(true);

https://developer.servicenow.com/dev.do#!/reference/api/rome/server_legacy/c_GlideRecordAPI#r_GlideR...

 

Please mark correct if that answered your question.