Creating a convert to another case UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 12:17 AM
We have a requirement to create a UI action to convert a security case (from another scope) to REQ > RITM > SCTASK.
We have written the script below. With our debugging it seems to be failing from line 31 "cart.addItem(item);"
Any ideas why and how to fix this issue. Thank you
function securitytorequests() {
// Check if assigned_to field is filled
// if (!g_form.getValue('assigned_to')) {
// alert("Please assign the record before converting it.");
// return false;
// }
var answer = confirm("Close this record and convert it to ICT Request? This action cannot be undone.");
if (answer == false) {
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'security_lab_convert_requests');
}
if (typeof window == 'undefined')
createReqCase();
function createReqCase() {
// create new Request and copy base values
var reqfor = current.requested_for;
var cartId = gs.generateGUID();
var cart = new sn_sc.CartJS();
var desc = "This request has been converted from " + current.number + "\n\n" + current.description;
var item = cart.addToCart({
"sysparm_id": "508f8d36db9d00104faa4815059619ee",
"sysparm_quantity": "1",
'requested_for': current.requested_for,
'short_description': current.short_description});
cart.addItem(item);
cart.setRequestedFor(reqfor);
//var checkoutVals = cart.checkoutCart();
var cartDetails = cart.orderNow(item);
// var rc = cart.placeOrder();
var _reqSysID = rc.sys_id;
current.transferred_to = _reqSysID;
var _reqItemGr = new GlideRecord('sc_req_item');
_reqItemGr.addQuery('request', _reqSysID);
_reqItemGr.query();
if (_reqItemGr.next()) {
}
var grTasks = new GlideRecord('sc_task');
grTasks.addQuery('parent', _reqItemGr.sys_id);
grTasks.query();
if (grTasks.next()) {
grTasks.assignment_group = '678a01c81b75a4d0749933fccc4bcbad'; //core app
grTasks.assigned_to = reqFor;
grTasks.update();
}
// copy attachments from INC to RITM and queue event for notification
GlideSysAttachment.copy('x_auuot_tua_security_security_case', current.sys_id, 'sc_req_item', grRITM.sys_id);
GlideSysAttachment.copy('x_auuot_tua_security_security_case', current.sys_id, 'sc_task', grSCTASK.sys_id);
gs.eventQueue('x_auuot_tua_security.security_lab_convert_reque', current, '', '');
//update and close security case
current.work_notes = "This job has been closed after being converted to " + grRITM.number + " and " + grSCTASK.number + ".";
//current.close_code = "Closed/Resolved by Caller";
current.state = 3;
current.update();
//redirect to RITM/SCTASK
action.setRedirectURL("/sc_task.do?sys_id=" + grSCTASK.sys_id);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 12:30 AM - edited 08-22-2023 12:31 AM
Hi
on https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/sn_sc-namespace/c_CartJSScoped you are provided with many code examples to make your code working
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 12:31 AM
I believe this line won't work in scoped app
var cartId = gs.generateGUID();
remove that line as you are not using that
Also replace this line
cart.addItem(item); -> cart.addToCart(item);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 03:55 AM
Hi Ankur,
It seems like it's moving further now, but it's not recording the current case information and transferring to the new case.
Eg Security Case Short Description now needs to go to Req > RITM > SCTASK short description