Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
What is wrong in the below code?
I'm getting below error and shared the code what I used.. also, catalog item is avaialble for all users... I created a new user criteira and added sn_internal and snc_externals roles to that user criteira..
Error:: Create Request : did not create or update sc_request using current
Code::
(function runAction(current, event, email, logger, classifier) {
var subject = email.subject;
var cart = new sn_sc.CartJS();
if (subject.toLowerCase().startsWith("test123")) {
var catalogItemSysId = '8c456b1d938fba1030c3baba2bba101c';
cart.addToCart({
sysparm_id: catalogItemSysId,
sysparm_quantity: 1,
variables: {
additional_information: email.body_html
}
});
cart.checkoutCart();
}
})(current, event, email, logger, classifier);
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Sathwik1
Try with this simple code:
(function runAction(current, event, email, logger, classifier) {
createRequest();
function createRequest() {
if (email.subject.toLowerCase().startsWith("test123")) {
var cart = new Cart();
var item = cart.addItem('8c456b1d938fba1030c3baba2bba101c');
cart.setVariable(item, 'additional_information', email.body_text);
cart.setVariable(item, 'requested_for', <reqFor_sysid>);
var rc = cart.placeOrder();
updateRequest(rc.sys_id, reqFor_sysid);
}
}
function updateRequest(req, reqfor) {
var grReq = new GlideRecord('sc_request');
grReq.addQuery('sys_id', req);
grReq.query();
if (grReq.next()) {
grReq.requested_for = reqfor;
// Set what other field value you want to set for REQ
grReq.update();
}
}
15 REPLIES 15
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what debugging did you do?
Did you try running that CartJS script in background and see if it create REQ and RITM?
Regards,
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
