- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 11:49 PM
In the form context menu, I need to add UI actions for Standard change, Normal change, and Emergency change.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 04:25 AM
@Krishna142 You can check OOTB UI Actions for these on Incident table and with slight changes create a new UI Action for sc_task table.
Create a new reference field (references change_request table) called with Label Change Request and name as u_rfc.
Normal Change:
- Open the link https://YOUR_INSTANCE_NAME.service-now.com/sys_ui_action.do?sys_id=30c9566dc61122740030e173564c1c74
- From context menu click on Insert and Stay
- Change the table name to sc_task
- Then condition to current.state != 3 && current.state != 4 && current.state != 7 && gs.hasRole("itil,sn_change_write") && gs.fieldExists('sc_task', 'u_rfc') && current.u_rfc.nil()
- Then in the script field use the following code and save the record.
(function(current, previous, gs, action) {
var stdChgCatalogActive = GlidePluginManager.isActive("com.snc.change_management.standard_change_catalog");
if (stdChgCatalogActive) {
var target = {};
target.table = current.getTableName();
target.sysid = current.getUniqueValue();
target.field = 'u_rfc';
try {
target.isWorkspace = (typeof RP == 'undefined');
}
catch (err) {
target.isWorkspace = false;
}
gs.getSession().putProperty('change_link', target);
}
var changeRequest = ChangeRequest.newNormal();
changeRequest.setValue("short_description", current.short_description);
changeRequest.setValue("description", current.description);
changeRequest.setValue("cmdb_ci", current.cmdb_ci);
if (changeRequest.hasValidChoice('priority', current.priority))
changeRequest.setValue("priority", current.priority);
changeRequest.setValue("sys_domain", current.sys_domain);
changeRequest.setValue("company", current.company);
var sysId = changeRequest.insert();
if (!stdChgCatalogActive) {
current.u_rfc = sysId;
current.update();
var sctUrl = "<a href='" + current.getLink(true) + "'>" + current.getDisplayValue() + "</a>";
gs.addInfoMessage(gs.getMessage("Normal Change {0} created from {1}", [changeRequest.getValue("number"), sctUrl]));
}
action.setReturnURL(current);
action.setRedirectURL(changeRequest.getGlideRecord());
})(current, previous, gs, action);
Standard Change:
Repeat the same steps as in Normal change, with the following script changes.
Condition: current.state != 3 && current.state != 4 && current.state != 7 && gs.hasRole("itil,sn_change_write") && gs.fieldExists('sc_task', 'u_rfc') && current.u_rfc.nil()
Script:
action.setRedirectURL(new StdChangeUtils().getURLForTask(current, 'u_rfc'));
Emergency Change:
Repeat the same steps as in Normal change, with the following script changes.
Condition: current.state != 3 && current.state != 4 && current.state != 7 && gs.hasRole("itil,sn_change_write") && gs.fieldExists('sc_task', 'u_rfc') && current.u_rfc.nil()
Script:
(function(current, previous, gs, action) {
var target = {};
target.table = current.getTableName();
target.sysid = current.getUniqueValue();
target.field = 'u_rfc';
try {
target.isWorkspace = (typeof RP == 'undefined');
}
catch (err) {
target.isWorkspace = false;
}
gs.getSession().putProperty('change_link', target);
var changeRequest = ChangeRequest.newEmergency();
changeRequest.setValue("short_description", current.short_description);
changeRequest.setValue("description", current.description);
changeRequest.setValue("cmdb_ci", current.cmdb_ci);
if (changeRequest.hasValidChoice('priority', current.priority))
changeRequest.setValue("priority", current.priority);
changeRequest.setValue("sys_domain", current.sys_domain);
changeRequest.setValue("company", current.company);
changeRequest.insert();
action.setReturnURL(current);
action.setRedirectURL(changeRequest.getGlideRecord());
})(current, previous, gs, action);
That's it!
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 12:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 02:36 AM
Hello Anvesh,
Greetings!!!
On "sc_task" table form, I need to implement these UI actions/Form context menus.
Thanks,
Krishna.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 04:25 AM
@Krishna142 You can check OOTB UI Actions for these on Incident table and with slight changes create a new UI Action for sc_task table.
Create a new reference field (references change_request table) called with Label Change Request and name as u_rfc.
Normal Change:
- Open the link https://YOUR_INSTANCE_NAME.service-now.com/sys_ui_action.do?sys_id=30c9566dc61122740030e173564c1c74
- From context menu click on Insert and Stay
- Change the table name to sc_task
- Then condition to current.state != 3 && current.state != 4 && current.state != 7 && gs.hasRole("itil,sn_change_write") && gs.fieldExists('sc_task', 'u_rfc') && current.u_rfc.nil()
- Then in the script field use the following code and save the record.
(function(current, previous, gs, action) {
var stdChgCatalogActive = GlidePluginManager.isActive("com.snc.change_management.standard_change_catalog");
if (stdChgCatalogActive) {
var target = {};
target.table = current.getTableName();
target.sysid = current.getUniqueValue();
target.field = 'u_rfc';
try {
target.isWorkspace = (typeof RP == 'undefined');
}
catch (err) {
target.isWorkspace = false;
}
gs.getSession().putProperty('change_link', target);
}
var changeRequest = ChangeRequest.newNormal();
changeRequest.setValue("short_description", current.short_description);
changeRequest.setValue("description", current.description);
changeRequest.setValue("cmdb_ci", current.cmdb_ci);
if (changeRequest.hasValidChoice('priority', current.priority))
changeRequest.setValue("priority", current.priority);
changeRequest.setValue("sys_domain", current.sys_domain);
changeRequest.setValue("company", current.company);
var sysId = changeRequest.insert();
if (!stdChgCatalogActive) {
current.u_rfc = sysId;
current.update();
var sctUrl = "<a href='" + current.getLink(true) + "'>" + current.getDisplayValue() + "</a>";
gs.addInfoMessage(gs.getMessage("Normal Change {0} created from {1}", [changeRequest.getValue("number"), sctUrl]));
}
action.setReturnURL(current);
action.setRedirectURL(changeRequest.getGlideRecord());
})(current, previous, gs, action);
Standard Change:
Repeat the same steps as in Normal change, with the following script changes.
Condition: current.state != 3 && current.state != 4 && current.state != 7 && gs.hasRole("itil,sn_change_write") && gs.fieldExists('sc_task', 'u_rfc') && current.u_rfc.nil()
Script:
action.setRedirectURL(new StdChangeUtils().getURLForTask(current, 'u_rfc'));
Emergency Change:
Repeat the same steps as in Normal change, with the following script changes.
Condition: current.state != 3 && current.state != 4 && current.state != 7 && gs.hasRole("itil,sn_change_write") && gs.fieldExists('sc_task', 'u_rfc') && current.u_rfc.nil()
Script:
(function(current, previous, gs, action) {
var target = {};
target.table = current.getTableName();
target.sysid = current.getUniqueValue();
target.field = 'u_rfc';
try {
target.isWorkspace = (typeof RP == 'undefined');
}
catch (err) {
target.isWorkspace = false;
}
gs.getSession().putProperty('change_link', target);
var changeRequest = ChangeRequest.newEmergency();
changeRequest.setValue("short_description", current.short_description);
changeRequest.setValue("description", current.description);
changeRequest.setValue("cmdb_ci", current.cmdb_ci);
if (changeRequest.hasValidChoice('priority', current.priority))
changeRequest.setValue("priority", current.priority);
changeRequest.setValue("sys_domain", current.sys_domain);
changeRequest.setValue("company", current.company);
changeRequest.insert();
action.setReturnURL(current);
action.setRedirectURL(changeRequest.getGlideRecord());
})(current, previous, gs, action);
That's it!
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:37 AM