- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2024 08:08 AM
Hi all,
Little explanation of what we're doing. We have a catalog item where the end user can fill in a number of fields which will then log a RITM record for our change management team to then create as a Change Request. We want to semi-automate this part of the process with a UI Action however I'm having a bit of both setting the change type based on what the end user has selected on the form.
As you can see below, the user can select 'Non-Production' as an option below. By default the change created will be a 'Normal' type, but if they select this then we want it to change to 'Non-Production.
Here is my current UI Action script with the top of it trying to define what they've selected.
var env = current.variables.request_type;
if (env == "Production"){
var chgtype = 'non_production';
}
var change = new GlideRecord("change_request");
change.newRecord();
change.short_description = current.short_description;
change.description = current.description;
change.assignment_group = current.assignment_group.sys_id;
change.work_notes = "This Change has been created from " + current.number;
change.risk = '4';
change.type = chgtype;
var sysId = change.insert();
current.parent = change.sys_id;
current.work_notes = "Change " + change.number + " has been created for this request";
current.update();
var incUrl = "<a href='" + current.getLink(true) + "'>" + current.getDisplayValue() + "</a>";
gs.addInfoMessage(gs.getMessage("Normal Change {0} created from {1}", [change.getValue("number"), incUrl]));
action.openGlideRecord(change);
However it's not working, I'm sure it's just a syntax thing but would appreciate someone with a bit more experience to look it over and let me know where I've done wrong.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2024 08:56 AM
Hi @LRhodes,
Thanks for clarifying, I believe I understand the requirement.
Based on the code you've provided, whilst you've mentioned the default change type value, I don't see it set/passed. Is this set on the Change Request table itself or something in the UI Action or a Catalog variable?
If this is not being set at the Change Request table level or by some after insert Business Rule or something, then you can set this in the UI Action by adding the following syntax at the top (Assuming I've understood your requirement correctly)
var env = current.variables.request_type;
if (env == "Non Production"){
var chgtype = 'non_production';
}
if (env != "Non Production"){
var chgtype = 'normal';
}
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2024 08:26 AM
Hi @LRhodes,
I'm struggling a little to make sense of the final sentence. Can you clarify and confirm this please:
"As you can see below, the user can select 'Non-Production' as an option below. By default the change created will be a 'Normal' type, but if they select this then we want it to change to 'Non-Production."
Should this be, if the Change type is Normal, it should change to 'Production'?
Please confirm.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2024 08:30 AM
Sorry Robbie,
So by default if the user filling in the form selects any options other than 'Non-Production' then we want the Change Request type to be Normal (this is achieved by doing nothing in the script as all new changes are set to Normal by default).
If they select Non-Production then we want the type on the Change Request form to also be Non-Production when the UI Action is triggered to create a change from the requested item form.
Hopefully that's a bit clearer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2024 08:56 AM
Hi @LRhodes,
Thanks for clarifying, I believe I understand the requirement.
Based on the code you've provided, whilst you've mentioned the default change type value, I don't see it set/passed. Is this set on the Change Request table itself or something in the UI Action or a Catalog variable?
If this is not being set at the Change Request table level or by some after insert Business Rule or something, then you can set this in the UI Action by adding the following syntax at the top (Assuming I've understood your requirement correctly)
var env = current.variables.request_type;
if (env == "Non Production"){
var chgtype = 'non_production';
}
if (env != "Non Production"){
var chgtype = 'normal';
}
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie