- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 12:26 AM
Hello,
I have created a UI action to convert to service request.When I click on it Incident gets cancelled and a new service request will be created..
I need to trigger a notification for the end user..
How can I create a event in this UI action.
//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()){
fp.parent = current.sys_id;
fp.watch_list = current.watch_list.getDisplayValue().toString();
fp.cmdb_ci = current.u_application;
fp.update();
}
action.setRedirectURL(rc);
}
// //function CreateRequestserver()
// //{
// gs.log('Jun9 :::: Inside ');
// var sysidOfItem = '352aa021db81ee4042c7f1fcbf961974';
// var cartId = GlideGuid.generate(null);
// var cart = new Cart(cartId);
// var item = cart.addItem(sysidOfItem);
// cart.setVariable(item, 'title', current.short_description);
// cart.setVariable(item, 'requested_for' , current.caller_id);
// cart.setVariable(item, 'assignment_group', current.assignment_group);
// var rc = cart.placeOrder();
// var message = 'Request ' + rc.number + ' created.<br />';
// current.incident_state = 8;
// current.resolved_by = gs.getUserID();
// current.close_notes = "Request ("+ rc.number +") created in place of this incident";
// current.work_notes = "Request ([code]<a href='/sc_request.do?sysparm_query=number="+ rc.number +"' target='_blank'>"+rc.number+"</a>[/code]) created in place of this incident";
// current.close_code = "Solved (Permanently)";
// 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 request = new GlideRecord('sc_request');
// if(request.get('number',rc.number)){
// action.setRedirectURL(request.getLink());
// }
// //}
Thanks
Saranya
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 02:44 AM
Hi
Go to EVENT Registry >> click on new button
Create a new event for the table.
Go to notifications change open the notification which need to be sent when UI action is clicked
Change the when condition in notification to
Send when >> Event is fired
Event name >> Name of the new event created.
Now in the ui action add the following code
//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()){
fp.parent = current.sys_id;
fp.watch_list = current.watch_list.getDisplayValue().toString();
fp.cmdb_ci = current.u_application;
fp.update();
gs.eventQueue("Name of the new event created", current, gs.getUserID(), gs.getUserName()); // This will trigger notification.
}
action.setRedirectURL(rc);
}
Please like or mark correct based on the impact of response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 02:44 AM
Hi
Go to EVENT Registry >> click on new button
Create a new event for the table.
Go to notifications change open the notification which need to be sent when UI action is clicked
Change the when condition in notification to
Send when >> Event is fired
Event name >> Name of the new event created.
Now in the ui action add the following code
//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()){
fp.parent = current.sys_id;
fp.watch_list = current.watch_list.getDisplayValue().toString();
fp.cmdb_ci = current.u_application;
fp.update();
gs.eventQueue("Name of the new event created", current, gs.getUserID(), gs.getUserName()); // This will trigger notification.
}
action.setRedirectURL(rc);
}
Please like or mark correct based on the impact of response.