Custom UI action to create CR from incident is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 12:37 AM - edited 05-09-2024 12:37 AM
I have a scoped custom applications with two tables x_scoped_incident and x_scoped_change_request. These two tables inherit from the global incident and Change Request tables and mimic similar functionalities.
I have a requirement to create a custom UI Action on the Scoped Incident Form, which will create a Change Request on the Scoped Change Request table. I've been reviewing the global Create Normal Change UI action however I don't know what to replace the "ChangeRequest.newNormal();" to reflect my custom Change Request table.
(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 = '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.rfc = sysId;
current.update();
var incUrl = "<a href='" + current.getLink(true) + "'>" + current.getDisplayValue() + "</a>";
gs.addInfoMessage(gs.getMessage("Normal Change {0} created from {1}", [changeRequest.getValue("number"), incUrl]));
}
action.setReturnURL(current);
action.setRedirectURL(changeRequest.getGlideRecord());
})(current, previous, gs, action);
Can someone please let me know what all changes I need to make and where?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 12:52 AM
It's not allowed to inherit from incident and change request tables without previous alignment with ServiceNow! So please reach out to your ServiceNow contact and clarify the technical impacts as well as the license-related aspects!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 01:22 AM
I think here the issue is that in the above script global script include is called. here :
var changeRequest = ChangeRequest.newNormal();
It works for the service OOTB change management as it is in the global scope. But it won't work in scoped application. This link has the solution on how you can call global scipt includes in scoped application. You can try it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 04:00 AM
Hey @Dhanashree1 ,
I don't need to call a global script include, rather I need it to make a record on my table and then redirect the form to it. I was successful in creating the record using Gliderecord insert action, however it does not redirect to the scoped change request table.
Do you know how I can redirect to a new record that was created in a gliderecord insert action in the same script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 07:28 AM
Hey @Navaneeth1
Try logging changeRequest.getGlideRecord(), my guess is it's not returning the right value because the SI itself is using an API that doesn't have a scoped variant. You might have to build the redirect yourself, though as @Maik Skoddow said you're really not supposed to be extending Incident or Change. If you've got a solid reason and you've vetted it out with SN then no worries.