- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2017 11:48 AM
Hi,
This is the requirement.
1. Create a Request ticket from an Incident. When 'Create Request' is clicked, it should trigger the current Incident to canceled state and create a request ticket with the details provided in the Incident form.
2. Also, vice versa. Create a Incident ticket from Request. When 'Create Incident' is clicked on the Request form, it should trigger the current request to canceled state and create an Incident ticket with the details provided in the request form. Has anyone does this?
Can anyone put me in the right direction and tell how to do this?
Thanks,
Rajini
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 05:37 AM
Well this is what we use:
UI Action
//Client-side 'onclick' function
function ReqWarning() {
var answer = confirm("Please confirm Request to Incident Action.");
if (answer == false) {
return false;
}
gsftSubmit(null,g_form.getFormElement(),'cancel_req_create_inc');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
//serverCancelPrj();
createIncident();
function createIncident() {
var inc = new GlideRecord("incident");
inc.short_description = current.short_description;
inc.description ="" + "Converted to Incident from: " + sc_req_item.request.number + "\n" + "\n\n" + "Description: " + current.description + '\n\n' + current.comments.getJournalEntry(3) + '\n\n' + current.work_notes.getJournalEntry(3);
//inc.priority = current.priority;
//inc.u_current_phone__ = current.u_current_phone;
//inc.location = current.location;
//inc.assignment_group = "f2a518706f7d91005ce5d2054b3ee4ca"; //Help Desk - to make sure INC has an group, then HD can re-assign
//inc.u_room = current.u_room;
//inc.u_affected_workstation.ip_address = current.u_ip;
inc.caller_id = current.request.requested_for;
inc.location = current.location;
inc.u_current_phone = current.u_phone;
inc.u_region = current.location.u_region;
inc.parent = current.request;
inc.cmdb_ci = current.cmdb_ci;
inc.impact = 3;
inc.urgency = 3;
current.parent = inc.insert();
current.comments = "" + "Converted Request to Incident: " + inc.number;
current.close_notes = "Converted Request to Incident: " + inc.number;
abortKids();
current.state = 4;
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'incident', inc.sys_id);
current.update();
gs.addInfoMessage("Remember to set Assignment Group");
gs.addInfoMessage("Incident " + inc.number + " created");
action.setRedirectURL(inc);
action.setReturnURL(current);
}
function abortKids() {
if (current.sys_id == '')
return;
var kids = new GlideRecord('sc_task');
kids.addQuery('parent', current.sys_id);
kids.query();
while (kids.next()) {
kids.state = 4;
kids.close_notes = "Task closed - Request Converted to Incident";
kids.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2018 04:07 PM
I was able to implement this solution in one of my instances and it is working. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2017 08:26 AM
Thank you so much. I will try this and post my comments soon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2018 07:20 AM
Did anyone find a way to "Create a Incident ticket from Request. When 'Create Incident' is clicked on the Request form, it should trigger the current request to canceled state and create an Incident ticket with the details provided in the request form." bit?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 05:37 AM
Well this is what we use:
UI Action
//Client-side 'onclick' function
function ReqWarning() {
var answer = confirm("Please confirm Request to Incident Action.");
if (answer == false) {
return false;
}
gsftSubmit(null,g_form.getFormElement(),'cancel_req_create_inc');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
//serverCancelPrj();
createIncident();
function createIncident() {
var inc = new GlideRecord("incident");
inc.short_description = current.short_description;
inc.description ="" + "Converted to Incident from: " + sc_req_item.request.number + "\n" + "\n\n" + "Description: " + current.description + '\n\n' + current.comments.getJournalEntry(3) + '\n\n' + current.work_notes.getJournalEntry(3);
//inc.priority = current.priority;
//inc.u_current_phone__ = current.u_current_phone;
//inc.location = current.location;
//inc.assignment_group = "f2a518706f7d91005ce5d2054b3ee4ca"; //Help Desk - to make sure INC has an group, then HD can re-assign
//inc.u_room = current.u_room;
//inc.u_affected_workstation.ip_address = current.u_ip;
inc.caller_id = current.request.requested_for;
inc.location = current.location;
inc.u_current_phone = current.u_phone;
inc.u_region = current.location.u_region;
inc.parent = current.request;
inc.cmdb_ci = current.cmdb_ci;
inc.impact = 3;
inc.urgency = 3;
current.parent = inc.insert();
current.comments = "" + "Converted Request to Incident: " + inc.number;
current.close_notes = "Converted Request to Incident: " + inc.number;
abortKids();
current.state = 4;
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'incident', inc.sys_id);
current.update();
gs.addInfoMessage("Remember to set Assignment Group");
gs.addInfoMessage("Incident " + inc.number + " created");
action.setRedirectURL(inc);
action.setReturnURL(current);
}
function abortKids() {
if (current.sys_id == '')
return;
var kids = new GlideRecord('sc_task');
kids.addQuery('parent', current.sys_id);
kids.query();
while (kids.next()) {
kids.state = 4;
kids.close_notes = "Task closed - Request Converted to Incident";
kids.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 04:34 AM
...and then cancel the parent Request, if there are no active RITM's inside:
function cancelRequest() {
if (current.sys_id == '')
return;
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.request.sys_id);
ritm.addActiveQuery();
ritm.query();
if (!ritm.next()) {
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', current.request.sys_id);
req.query();
if (req.next()) {
req.request_state = 'closed_skipped';
req.active = false;
req.comments = "Request Converted to Incident";
req.update();
}
}
}