RITM UI action seems to send out a rejection email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago - last edited a month ago
I have a ui action for RITMs that converts to them to incidents and for some reason seems to kick out a rejection email. I have no idea why a rejection email would fire. We have no approvals in this workflow for this catalog item.
If anyone can help me troubleshoot this mystery, I would appreciate it!
/* Construct RITM Links
-----------------------------------------------------------------------------------------------------------------------*/
var ritmTable = current.getTableName();
var ritmSysID = current.getUniqueValue();
var ritmNum = current.getValue('number');
//SERVICE PORTAL: construct a link to the original RITM for inclusion in the customer comments of the incident.
var spRITMLink = spLink(ritmTable,ritmSysID,ritmNum);
//PLATFORM: construct a link to the parent RITM that itil users can use to navigate from the newly created incident.
var platformRITMLink = platformLink(ritmTable,ritmSysID,ritmNum);
/* Construct comments and work notes
-----------------------------------------------------------------------------------------------------------------------*/
var comments = '[code]Hello:' + '<br>' + 'We have converted your Request Ticket into an Incident ticket. Based on the issue you have described, we believe this issue needs to be worked as something that is an Incident or something that is broken. We will continue to assist you with your issue until it is resolved. You may click here to view your previous Request that is now closed incomplete: ' + spRITMLink + '. Thank you! ' + '<br><br>';
comments += '<strong>Details from your previous Request Ticket:</strong><br>';
comments += '<table>';
//Query RITM variables, utilising the variable label and displayValue to build a table.
var vars = current.variables.getElements();
for (var i = 0; i < vars.length; i++){
var question = vars[i].getQuestion();
comments += '<tr><td>' + question.getLabel() + ':</td><td>' + question.getDisplayValue() + '</td></tr>';
}
comments += '</table>[/code]';
//include customer comments from the RITM (-1 returns all journal entries for specified journal field)
var ritmComments = current.comments.getJournalEntry(-1);
if (JSUtil.notNil(ritmComments)) {
comments += '[code]<br><br><strong>Customer comments from ' + ritmNum + '</strong><br>[/code]';
comments += ritmComments;
}
var workNotes = 'A link to previous ticket opened by the end user: [code]' + platformRITMLink + '[/code].';
/* Ascertain the Assignment Group
-----------------------------------------------------------------------------------------------------------------------*/
var assignmentGroup = getAssignmentGroup(ritmSysID);
/* Create Incident
-----------------------------------------------------------------------------------------------------------------------*/
var inc = new GlideRecord("incident");
inc.caller_id = current.request.requested_for;
inc.assignment_group = assignmentGroup;
inc.short_description = current.short_description;
inc.description = current.description;
inc.cmdb_ci = current.cmdb_ci;
inc.impact = current.impact;
inc.urgency = current.urgency;
inc.priority = current.priority;
inc.comments = comments;
inc.work_notes = workNotes;
inc.parent = ritmSysID;
inc.u_type = 'IT';
inc.contact_type = current.contact_type;
inc.watch_list = current.watch_list;
var incSysID = inc.insert();
var incTable = inc.getTableName();
var incNum = inc.getValue('number');
/* Copy attachments to Incident
-----------------------------------------------------------------------------------------------------------------------*/
//copy any RITM attachments to the newly created incident
GlideSysAttachment.copy(ritmTable, ritmSysID, incTable, incSysID);
/* Construct Incident Links
-----------------------------------------------------------------------------------------------------------------------*/
//SERVICE PORTAL: construct a link to the Incident for inclusion in the customer comments of the RITM.
var spIncLink = spLink(incTable,incSysID,incNum);
//PLATFORM: construct a link to the Incident that itil users can use to navigate from the parent RITM in platform.
var platformIncLink = platformLink(incTable,incSysID,incNum);
/* Update comments and work notes
-----------------------------------------------------------------------------------------------------------------------*/
current.comments = 'We have converted your Request Ticket into an Incident ticket. You do not need to do anything to receive further assistance from us. Thank you!';
current.work_notes = 'A link to newly created incident for Agents: [code]' + platformIncLink + '[/code].';
/* Close SC_Task as "Incomplete"
----------------------------------------------------------------------------------------------------------------------*/
var scTask = new GlideRecord("sc_task");
scTask.addQuery("request_item", current.sys_id);
scTask.query();
while(scTask.next()) {
scTask.state = 4;
scTask.active = false;
scTask.update();
}
/* Close RITM as "Closed Incomplete"
-----------------------------------------------------------------------------------------------------------------------*/
current.setValue('state', '4');
current.setValue('stage', 'closed_incomplete');
current.setValue('active', 'false');
var mySysID = current.update();
gs.addInfoMessage(gs.getMessage("Incident {0} created", incNum));
action.setRedirectURL(inc);
action.setReturnURL(current);
/* Link builders
-----------------------------------------------------------------------------------------------------------------------*/
function spLink(table,sysID,num){
var link = '<a title="Service Portal Link" href="it?id=ticket&table=' + table + '&sys_id=' + sysID + '">' + num + '</a>';
return link;
}
function platformLink(table,sysID,num){
var link = '<a title="Platform Link" href="' + table + '.do?sys_id=' + sysID + '">' + num + '</a>';
return link;
}
/* Locate the last assignment group
-----------------------------------------------------------------------------------------------------------------------*/
function getAssignmentGroup(ritmSysID) {
/* Return all active tasks relating to RITM ordered by newest task first i.e. last created ticket. */
var tskGrp = new GlideRecord('sc_task');
tskGrp.addActiveQuery();
tskGrp.addQuery('request_item', ritmSysID);
tskGrp.orderByDesc('number');
tskGrp.orderByDesc('sys_created_on');
tskGrp.query();
var assignmentGroup = '';
if(tskGrp.next()) {
//set the assignment group to the last generated active task's assignment group
assignmentGroup = tskGrp.getValue('assignment_group');
}
else {
/* Default to the Service Desk if a assignment group cannot be found */
//NOTE: This is a custom system property, containing the group sys_id for your service desk
//You will need to create it in sys_poperties if you want to fall back to your service desk
assignmentGroup = gs.getProperty('sc.service_desk');
}
return assignmentGroup;
}
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Is this a custom button or OOTB one?
you are doing current.update() which might be triggering some backend logic and hence rejection email might be getting triggered.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
It was a custom button an admin found on here that was put in a while back. For the most part it works great... but the problem is with the rejection, it kicks off a extra email notification to the end user about a rejection that doesn't exist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hello @RBlor
In your case and reading the statement it feels that Ui Action is not OOTB one, also your code is updating state & stage. Now since this field are getting updated there might be any condition on notification which is getting satisfied and which may be sending that rejection email.
You can try to open email sent out from logs, and see if any event is attached to it which may get trigger from any BR due to field changes OR check notification what condition is written down and see if any of the fields are set with same value.
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.