When we click on the UI Action to open in a new Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 03:57 AM
we have a ui action = "create change" with client callable unchecked
Below is the code script in ui actions
if( current.type == 'change' ){
var resultAsObject = true;
var demandUtil = new AjaxCreateRelatedEntityFromDemand();
var changeObj = demandUtil.createChange(current.sys_id, resultAsObject);
var changeId = changeObj.sys_id;
var number = changeObj.number;
var displayLabel = changeObj.label;
var change;
var message;
var link;
if (changeId) {
change = new GlideRecord('change_request');
change.addQuery("sys_id", changeId);
change.query();
if(change.next()){
link = ' <a href ="/change_request.do?sysparm_query=number%3D' + number + '">'+ number +'</a>';
message = gs.getMessage("{0} {1} has been created");
message = message.replace("{0}", displayLabel);
message = message.replace("{1}", link);
gs.addInfoMessage(message);
}
} else {
message = gs.getMessage("Error creating {0}");
message = message.replace("{0}", displayLabel);
gs.addErrorMessage(message);
}
action.setRedirectURL(current);
}
below is the script include
createChange: function(demand_id, resultAsObject) {
var demand;
var change;
var changeId;
var changeNumber;
var tableDisplayName;
demand = this._getDemand(demand_id || this.getParameter('sysparm_sys_id'));
if (!demand) {
gs.log("Error creating demand");
return;
}
change = new GlideRecord('change_request');
change.initialize();
change.setValue("short_description", demand.short_description);
change.setValue("parent", demand.sys_id);
change.setValue('sys_domain', demand.sys_domain);
changeId = change.insert();
changeNumber = change.getValue('number');
tableDisplayName = change.getClassDisplayValue();
//update demand with change details
if (JSUtil.nil(demand.related_records))
demand.related_records = changeId;
else
demand.related_records = demand.related_records + "," + changeId;
demand.change = changeId;
demand.state = '8';
demand.stage = 'change';
demand.update();
if (new GlidePluginManager().isActive('com.snc.investment_planning_pmo')) {
var invst = new InvstDemandConversion(demand, change);
invst.updateExsistingInvestMentWhenDemandIsConverted();
}
return this._inExpectedFormat({
'sys_id': changeId,
'number': changeNumber,
'label': tableDisplayName
}, resultAsObject);
},
It is working fine when you try to click on "create change" it is in the same page with the change created with some field pre populate
My requirement is same but when I click on "create change" it should open in a new tab with some fields pre populated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 04:04 AM
Hi @Community Alums
in ServiceNow you cannot configure a button (UI Action) in a way that a new tab is opened when clicking on it.
You only can open a new tab in client-side code, but your UI Action seems to be server-side only.
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 04:11 AM
Hi @Maik Skoddow
when we use only the below code in UI action it will work for the new record
how can we configure in client script to achieve the requirement