- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2021 05:37 AM
Hello,
I am trying to create a UI action "create incident" button on the Interaction Form (not from Agent Workspace). With below script, it could create incident once clicking on a button but it will load from the same tab instead of open a new tab.
Could anyone please advise how to?
Condition: new GlideRecord("incident").canCreate() && ((current.isNewRecord() && current.canCreate()) || !current.isNewRecord())
Script:
var canCreateIncident = false;
if ((current.isNewRecord() && current.canCreate()) || (!current.isNewRecord() && current.canWrite()))
canCreateIncident = current.update();
else
canCreateIncident = true;
if (canCreateIncident) {
var inc = new GlideRecord("incident");
inc.initialize();
inc.caller_id = current.opened_for;
inc.short_description = current.short_description;
inc.description = current.u_description;
inc.insert();
//action.openGlideRecord(inc);
var url = 'https://'+ gs.getProperty('instance_name') + '.service-now.com/incident.do?sys_id=' + inc.sys_id;
action.setRedirectURL(url);
}
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2021 09:44 AM
Hi Bird,
In that case you have to use g_navigation api which is a client side api in your ui action and you would require a client callable script include to create the incident.
UI action code:-
Make sure to check client checkbox in ui action and specify the function name in the onClick section
function createIncident() {
var recordDetails = {
opened_for: g_form.getValue('opened_for'),
short_description: g_form.getValue('short_description'),
description: g_form.getValue('description')
};
var ga = new GlideAjax('IncidentUtil');
ga.addParam('sysparm_name', 'createIncident');
ga.addParam('sysparm_recordDetails', JSON.stringify(recordDetails));
ga.getXMLAnswer(openIncRecord);
function openIncRecord(answer) {
if (answer) {
g_navigation.open(answer, '_blank');
}
else {
g_form.addErrorMessage("There was an issue");
}
}
}
Script include:-
Make sure to check the client callable check box
var IncidentUtil = Class.create();
IncidentUtil.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
createIncident: function() {
try {
var recDetails = JSON.parse(this.getParameter('sysparm_recordDetails'));
var incGr = new GlideRecord('incident');
incGr.newRecord();
incGr.setValue('caller_id', recDetails.caller_id);
incGr.setValue('short_description', recDetails.short_description);
incGr.setValue('description', recDetails.description);
var incSysID = incGr.insert();
return "/incident.do?sys_id=" + incSysID;
}
catch(ex) {
gs.error("Incident creation error : " + ex);
return null;
}
},
type: 'IncidentUtil'
});
Thanks
Sourav

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2021 06:06 AM
Greetings!
For the condition, just below is fine.
Condition: new GlideRecord("incident").canCreate();
as the UI action will not be visible if the user cannot create incident then you do not have to write extra validation in script.
script:
var inc = new GlideRecord("incident");
inc.initialize();
inc.caller_id = current.opened_for;
inc.short_description = current.short_description;
inc.description = current.u_description;
var incNew = inc.insert(); //assign the sys_id of new record to a variable
var url = 'https://'+ gs.getProperty('instance_name') + '.service-now.com/incident.do?sys_id=' + incNew ;
action.setRedirectURL(url);
Regards
Vinayak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2021 07:04 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2021 07:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2021 07:28 AM
Hi Bird,
Do you want the incident to be created manually after a new incident form opens in a new tab? or you want to create the incident automatically and open the incident in a new tab?
Thanks
Sourav