- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 05:55 AM
Hello All,
I have the below script UI Action which converts RITM to INC.
I need help in opening the newly created INC in a new tab. How do I do it from client side as I now understand it cannot be done through server side
function openinc() {
var usrResponse = confirm('Are you sure you would like to proceed?');
if (usrResponse)
gsftSubmit(null, g_form.getFormElement(), 'transfer_incident');
}
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;
g_navigation.open(url);
}
@Ankur Bawiskar @Ravi Gaurav @Runjay Patel @Sandeep Rajput @Chuck Tomasi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2025 12:32 AM
I hope your UI action is client side
Script include is not client callable
seems you didn't copy it exactly what I gave in script include.
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
01-29-2025 06:14 AM
Hello @DB1
Check this thread which will be helpful to you.
Convert an RITM to an Incident - ServiceNow Community
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 06:49 AM
I tried but the redirect is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 07:06 AM
that's correct you cannot open in new tab using server side
The only way is this
1) make the UI action client side
2) use GlideAjax to create record, copy etc and update the current record
3) that script include function will return sysId and then you can open in new tab using g_navigation
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
01-29-2025 07:13 AM
something like this
UI Action:
function convertRecord() {
var usrResponse = confirm('Are you sure you would like to proceed?');
if (usrResponse) {
var ga = new GlideAjax('ConvertRecord');
ga.addParam('sysparm_name', 'convertMyRecord');
ga.addParam('sysparm_sysId', g_form.getUniqueValue());
ga.getXMLAnswer(function(answer) {
var url = "incident.do?sys_id=" + answer;
g_navigation.open(url, '_blank');
});
}
}
Script Include: Client callable
var ConvertRecord = Class.create();
ConvertRecord.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.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: 'ConvertRecord'
});
I hope you should enhance it based on your requirement and debug further with your developer skills.
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