Open Incident created from RITM via UI action in a new tab
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2025 11:57 PM
Hi All,
I am trying to open a Incident created via RITM in a new tab and I understand it is possible through SI and UI Action however it is not working for me
Script Include:
var PH_RITMToINC = Class.create();
PH_RITMToINC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
convertMyRecord: function() {
var ritmSysID = this.getParameter('sysparm_sysId');
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(ritmSysID)) {
var comments = 'Incident created from ' + ritm.number;
var inc = new GlideRecord("incident");
inc.initialize();
inc.caller_id = ritm.request.requested_for;
inc.short_description = ritm.short_description;
inc.cmdb_ci = ritm.cmdb_ci;
inc.assignment_group = ritm.assignment_group;
inc.business_service = ritm.business_service;
inc.impact = ritm.impact;
inc.urgency = ritm.urgency;
inc.description = ritm.variables.description;
inc.contact_type = 'self-service';
// inc.u_initiated_by = ritm.request.opened_by;
inc.comments = comments;
inc.parent = ritmSysID;
var incSysID = inc.insert();
GlideSysAttachment.copy(ritm.getTableName(), ritmSysID, inc.getTableName(), incSysID);
ritm.comments = 'RITM converted to ' + inc.number + '. Please use this reference from now on.';
ritm.state = 4;
ritm.update();
var taskRec = new GlideRecord('sc_task');
taskRec.addQuery('request_item', ritmSysID);
taskRec.addEncodedQuery('stateIN-5,1,2');
taskRec.query();
while (taskRec.next()) {
taskRec.state = 4;
taskRec.update();
}
return incSysID;
}
return '';
},
type: 'PH_RITMToINC'
});
UI Action:
gs.log("ans 1");
/*function openinc() {
gs.log("ans 2");
var usrResponse = confirm('Are you sure you would like to proceed?');
if (usrResponse) {
gs.log('ans inside loop');
var ga = new GlideAjax('PH_RITMToINC');
ga.addParam('sysparm_name', 'convertMyRecord');
ga.addParam('sysparm_sysId', g_form.getUniqueValue());
gs.log('ans inside loop' + g_form.getUniqueValue());
ga.getXMLAnswer(function(answer) {
gs.log("ans " + answer);
var url = "incident.do?sys_id=" + answer;
g_navigation.open(url, '_blank');
});
}
}*/
/*if (typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode() {
var ritmTable = current.getTableName();
var ritmSysID = current.getUniqueValue();
var ritmNum = current.getValue('number');
var comments = 'Incident created from ' + ritmNum;
var inc = new GlideRecord("incident");
inc.caller_id = current.request.requested_for;
//inc.assignment_group = assignmentGroup;
inc.short_description = current.short_description;
inc.cmdb_ci = current.cmdb_ci;
inc.assignment_group = current.assignment_group;
inc.business_service = current.business_service;
inc.impact = current.impact;
inc.urgency = current.urgency;
inc.description = current.variables.description;
inc.contact_type = 'self-service';
inc.u_initiated_by = current.request.opened_by;
inc.comments = comments;
inc.parent = ritmSysID;
var incSysID = inc.insert();
var incTable = inc.getTableName();
var incNum = inc.getValue('number');
GlideSysAttachment.copy(ritmTable, ritmSysID, incTable, incSysID);
current.comments = 'RITM converted to ' + incNum + '. Please use this reference from now on.';
current.state = 4;
//
var taskRec = new GlideRecord('sc_task');
taskRec.addQuery('request_item', current.sys_id);
taskRec.addEncodedQuery('stateIN-5,1,2');
taskRec.query();
while (taskRec.next()) {
taskRec.state = 4;
taskRec.update();
}
//
current.update();
//gs.log("state " + current.state);
gs.addInfoMessage(gs.getMessage("Incident {0} created", incNum));
//action.setRedirectURL(inc);
//action.setReturnURL(current);
//gs.setRedirect("incident.do?sys_id=" + incSysID);
var url = "incident.do?sys_id=" + incSysID;
gs.setRedirect(url, '_blank'); //g_navigation.open(url);
}*/
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2025 11:58 PM
Need help on the same please @Community Alums @Sachin9
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2025 12:32 AM
why to post duplicate question?
I already responded to your earlier question.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2025 08:00 PM