Convert Incident to Request via UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2016 05:36 PM
Hello,
I am trying to add a form button for a UI action that would convert an incident to a request. I know there is an OOB UI action to do this, but it currently brings you to the catalog to select the service and then you have to fill out all the variables for it. I have pieced together this script from other people who had similar questions on this forum and from the wiki. Currently it creates the request and it populates it with some of the incident fields like I want. I'm not great with JavaScript and I want to know if this is how I should even be going about this/thinking about this. I could have the UI action create a request item instead of a request, if that is a better idea. Can anyone please check this script and help advise.1
Requirements:
1. Create a Request from an Incident in one click
2. Prompt with notification for continue or not
3. Create request or request item (advise on this please)
4. Resolve current incident
5. Populate request with incident field values (at least important ones)
Thanks,
Sean
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
function createRequest(){
var answer = confirm(getMessage("This will create a request from this incident. Are you sure you want to do this?") );
if(answer == true){
gsftSubmit(null, g_form.getFormElement(), 'ebc381cfdb5ae20038b272fc0f961923'); //Set this to your Action ID
}
else{
return answer;
}
}
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();
function serverResolve(){
var req = new GlideRecord("sc_request");
req.short_description = current.short_description;
req.cmdb_ci = current.cmdb_ci;
req.description = current.description;
req.comments = current.comments;
req.priority = current.priority;
req.company = current.company;
req.sys_domain = current.sys_domain;
var sysID = req.insert();
current.request_id = sysID;
var mySysID = current.update();
//Close the current incident upon request creation
current.incident_state = IncidentState.RESOLVED;
current.update();
current.resolved_by = gs.getUserID();
gs.addInfoMessage("request " + req.number + " created");
gs.addInfoMessage("Incident" + incident.number + "has been resolved");
action.setRedirectURL(req);
action.setReturnURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2017 09:35 PM
Hello ramakrishna,
//Client-side 'onclick' function
function IncWarning() {
var answer = confirm("Incident will get Close Cancelled and new service request will be created.");
if (answer == false) {
return false;
}
gsftSubmit(null,g_form.getFormElement(),'cancel_inc_create_req');
}
createCart();
function createCart() {
var cart = new Cart();
var item = cart.addItem('352aa021db81ee4042c7f1fcbf961974');
cart.setVariable(item, 'requestor', current.caller_id.sys_id.toString());
cart.setVariable(item, 'requested_for', current.caller_id.sys_id.toString());
cart.setVariable(item, 'requested_by', current.caller_id.sys_id.toString());
cart.setVariable(item, 'short_description', current.short_description);
cart.setVariable(item, 'phone', current.u_current_phone);
cart.setVariable(item, 'location', current.location);
cart.setVariable(item, 'impacted_location', current.location);
cart.setVariable(item, 'description', 'Converted to Request from: ' + current.number + '\n\n' + "Incident Description: " + current.description + '\n\n' + current.comments.getJournalEntry(3) + '\n\n' + current.work_notes.getJournalEntry(3));
cart.setVariable(item, 'assignment_group', current.assignment_group);
cart.setVariable(item, 'assigned_to', current.assigned_to);
var rc = cart.placeOrder();
var message = 'Request ' + rc.number + ' created.<br />';
current.close_code = 'Not Solved (is a Request)';
current.close_notes = 'Opened in Error, converting to Misc Request';
current.comments = 'Converted Incident to Request: ' + rc.number;
//sets the REQ on the parent INC
current.u_request = rc.sys_id.toString();
current.reassignment_count = 1;
current.incident_state = 14;
GlideSysAttachment.copy('incident', current.sys_id, 'sc_request', rc.sys_id);
//Update saves incidents before going to the catalog homepage
current.update();
message += 'Incident <a target="_blank" href="/incident.do?sysparm_query=number=' + current.number + '">';
message += current.number+ '</a> has been resolved.';
gs.addInfoMessage(message);
var fp = new GlideRecord('sc_request');
fp.addQuery('sys_id', '=', rc.sys_id);
fp.query();
while (fp.next()){
gs.eventQueue("convertintosr.information", fp);
fp.parent = current.sys_id;
fp.short_description=current.short_description;
fp.watch_list = current.watch_list.getDisplayValue().toString();
fp.cmdb_ci = current.u_application;
fp.update();
}
action.setRedirectURL(rc);
}
Thanks
Saranya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2017 12:02 AM
Thank you saranya