Create Request UI Action from an item record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2024 08:41 AM
I have a client that wants to be able to create a request from within another requests item record. I copied the Create Request UI Action from Incident and added it to the item table. It works to the point where it generates the request but fails to set the parent on the request record to the item that generated it.
When this same UI Action is run from incident, the parent on the generated request record is set to the incident sys_id. I have reviewed all of the URL's through the process of creating the request. All of them are referencing the the parameters "sysparm_parent_sys_id=4136f3f3c3c80a90bf1e1c5ce0013165%26sysparm_parent_table=sc_req_item" correctly but the parent sys_id is not being set as the parent on the request record as it does on Incident.
This does not appear to be an issue in the dictionary entry of parent on request. I can manually select the correct item record as the parent.
Anyone know of a workaround for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2024 12:01 PM - edited ‎02-07-2024 12:05 PM
I suggest you post the UI definition script. As I see three OOB UI Actions named "Create Request" defined on the incident table. One uses the 'IncidentUtils' script include.
use something like 'var parentSID = g_form.getUniqueValue();'
and use 'parentSID' in the code to set value of the "parent".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2024 02:07 AM
Thanks Bert, forgot to include script. Here is the script I am using. I change the condition to only check for the itil role and set it as a button instead of context menu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2024 08:31 AM - edited ‎02-08-2024 08:35 AM
Hi Bob,
I haven't done much at all with Service Catalogs. But I do have example of creating a change_request record from an Incident using an UI Action. I see no logic (that I expected) to create a record in another table from a sc_req_item record. I would look at existing OOB UI Actions that do similar functions.
From what you post, it seems you need a line at the end like:
action.setRedirectURL(url);
The UI Action code from that I have from my example follows:
action.setRedirectURL(current);
var incidentRequest = (new IncidentUtils()).createRequest(current);
gs.addInfoMessage(gs.getMessage("Request {0} was created", incidentRequest));
The Script Include code follows.
var IncidentUtils = Class.create();
IncidentUtils.prototype = Object.extendsObject(IncidentUtilsSNC, {
initialize: function() {
IncidentUtilsSNC.prototype.initialize.call(this);
},
/***************Custom changes****************/
createRequest: function(currentIncident) {
// create sc_request record
var gr = new GlideRecord('sc_request');
gr.setValue('requested_for', currentIncident.caller_id);
gr.setValue('company', currentIncident.company);
gr.setValue('u_category', currentIncident.category);
gr.setValue('u_subcategory', currentIncident.subcategory);
gr.setValue('short_description', currentIncident.short_description);
gr.setValue('description', currentIncident.description);
gr.setValue('assignment_group', currentIncident.assignment_group);
gr.setValue('assigned_to', currentIncident.assigned_to);
gr.setValue('state', currentIncident.state);
var requestId = gr.insert();
gs.info('createRequest: created request: ' + requestId);
gr.get(requestId);
// update incident fields
current.state='7';
current.work_notes="Created " + gr.number;
current.close_code='6';
current.close_notes="Created " + gr.number;
var updResult = current.update();
gs.info('createRequest: incident update: ' + updResult);
return "<a href='/sc_request.do?sysparm_query=number=" + gr.number +"'>" + gr.number + "</a>";
},
type: 'IncidentUtils'
});
IncidentUtils.isCopyIncidentEnabled = function(current) {
var incidentUtils = new IncidentUtils();
return incidentUtils.isCopyIncidentFlagValid();
};
IncidentUtils.isCreateChildIncidentEnabled = function(current) {
var incidentUtils = new IncidentUtils();
return incidentUtils.isCreateChildIncidentFlagValid();
};
Hopefully, I have provided something useful here. maybe not. The above creates a 'sc_request' record from an 'incident' form.
If you post in the Developer forum, there is much wider participation.