
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Ever try to create a Request from an Incident?
How many actually remember to navigate back to the Incident? What about if you want to transfer an Incident to a Request?
If you're ever used the HR application, there is a great Transfer Case UI action available that allows you to transfer a case from one case to another. The UI action calls a UI page, and the UI page gets some data from a script includes. With a few small changes, you can create a similar experience when transferring an Incident to a Request. (BTW - You can also make a solution to create a STD Change from an Incident and have the two records linked together - finally!)
In the UI action - new dialogClass('Transfer incident') makes the call to the UI Page:
function transferCase() {
var sysId = g_form.getUniqueValue();
var dialogClass = GlideModal ? GlideModal : GlideDialogWindow;
var dialog = new dialogClass('Transfer incident');
dialog.setTitle(getMessage('Transfer Incident'));
dialog.setPreference('sysparm_sys_id', sysId);
dialog.setPreference('sysparm_table_name', g_form.getTableName());
dialog.setPreference('sysparm_subject_person', g_form.getValue('subject_person'));
dialog.render();
}
In the UI Page, HTML section, new TransfertoRequest().getCatItems() is the call to the script includes. You can see the area's to change any of the wording inside the dialog box:
We'll get back to the UI Page Processing Script. In the script includes, we're just querying the catalog items we want to present as options for transferring too. We've filtered out record producers, and STD Change Templates:
var TransferToRequest = Class.create();
TransferToRequest.prototype = {
initialize: function() {
},
getCatItems: function() {
var catitems = new GlideRecord("sc_cat_item");
catitems.addActiveQuery();
catitems.addQuery('sc_catalogs','e0d08b13c3330100c8b837659bba8fb4');
//filter out Record Producers
catitems.addQuery('sys_class_name', "!=", 'sc_cat_item_producer');
//filter out STD Change Templates
catitems.addQuery('sys_class_name', "!=", 'std_change_record_producer');
catitems.orderBy("sc_catalog");
catitems.orderBy("name");
catitems.query();
var result = [];
var categories = {};
while (catitems.next()) {
var categorySysId = catitems.category.sys_id;
var category = catitems.category.title.toString();
if (!categories[categorySysId]) {
categories[categorySysId] = {
display: category,
children: []
};
result.push(categories[categorySysId]);
}
categories[categorySysId].children.push({
sys_id : catitems.getUniqueValue(),
display : catitems.getDisplayValue(),
//template : catitems.getValue("template"),
parent : category
Now for the UI Page Processing Script. This is where all the work is done! If you're using New Call, this script looks very similar to the business rule CallTypeChanged to Request. We're sending some data to the cart, inserting the new record, and then cancelling the Incident since we've transferred it to a Request.
(function(_this) {
var originalTask = new GlideRecord(task_table_name);
if (!originalTask.get(task_sys_id)) {
gs.addErrorMessage(gs.getMessage("Could not find original case"));
return;
}
var reqFor = originalTask.caller_id;
var location = originalTask.caller_id.location;
var reqItem = selected_service;
var desc = originalTask.description;
var sdsc = originalTask.short_description;
//NEW_INCI_REF will trigger business rule Link back to the call that generated it
var comments = "NEW_INCI_REF:"+originalTask.sys_id+" - "+originalTask.description.substring(0,100);
var url = "com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=" + reqItem
+ "&sysparm_user=" + GlideStringUtil.urlEncode(reqFor)
+ "&sysparm_location=" + GlideStringUtil.urlEncode(location)
+ "&sysparm_special_instructions=" + GlideStringUtil.urlEncode(comments)
//+ "&sysparm_stack=" + current.getLink()
+ "&sysparm_sdsc=" + sdsc
+ "&sysparm_comments=" + originalTask.comments;
response.sendRedirect(url);
getCart();
function getCart() {
var cart = new GlideRecord('sc_cart');
var userid = gs.getUserID();
cart.addQuery('user', userid);
cart.query();
if (cart.next()) {
// We already have a cart so override the requested for value and empty it
cart.source_table = 'incident';
cart.requested_for = reqFor;
cart.special_instructions = comments;
cart.update();
var cartItems = new GlideRecord('sc_cart_item');
cartItems.addQuery('cart', cart.sys_id);
cartItems.deleteMultiple();
} else {
cart.initialize();
cart.user = userid;
cart.requested_for = reqFor;
cart.special_instructions = comments;
cart.insert();
}
// Cancel original case
originalTask.state = 8;
originalTask.close_code = 'Resolved';
originalTask.close_notes = 'Incident transferred to a Request';
//Populate group manager in assigned to if executed as admin
if (gs.hasRole('admin') && originalTask.assigned_to.nil())
originalTask.assigned_to = originalTask.assignment_group.manager;
if(originalTask.assigned_to.nil())
originalTask.assigned_to = gs.getUserID();
originalTask.comments = gs.getMessage("Incident was cancelled and transferred to a Request");
if (!originalTask.update()) {
gs.addErrorMessage(gs.getMessage("Failed to close original case"));
return;
}
}
})(this);
- - - - The end result - - - -
We have a couple of helper business rules. One to query any open Incident Task(s) and close them if the parent state changes to Canceled. Another to pull some data from the Incident into the request, including setting the parent field on the request with the incident, so the two are linked together for reference in the future.
I've attached an update set if you want to check it out. I hope you find this information helpful!
We are already working on another for creating a STD Change from an Incident.
- 3,186 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.