- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2022 12:45 PM
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.
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2022 02:03 PM
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);
Please mark correct if that answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2022 02:03 PM
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);
Please mark correct if that answered your question.