The CreatorCon Call for Content is officially open! Get started here.

UI Action : Create Incident button and need it to open a new tab instead of loading the same page.

Bird1
Mega Sage

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);

}

1 ACCEPTED SOLUTION

Sourav16
Kilo Guru

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

find_real_file.png 

 

find_real_file.png

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

find_real_file.png

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

View solution in original post

14 REPLIES 14

Incident Create Automatically (copy opened for to caller and short description to short description) and open the incident in a new tab.

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

find_real_file.png 

 

find_real_file.png

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

find_real_file.png

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

are you not using workspace client script?

with action.setRedirectURL(url) you cannot open new tab

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Bird 

for UI actions in workspace you need to use workspace client script

use this

function onClick(g_form) {

	var inc = new GlideRecord("incident");
	inc.initialize();
	inc.caller_id = g_form.getValue('opened_for');
	inc.short_description = g_form.getValue('short_description');
	inc.description = g_form.getValue('u_description');
	inc.insert();
	var url = '/incident.do?sys_id=' + inc.sys_id;
	var win = top.window.open(url, '_blank');
	win.focus();

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I don't need it on agent workspace as my user is not familiar with it much.

They prefer to add a new button on IMS form

 

find_real_file.png