- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 06:21 AM
Hello!
I have a create change UI action from an open task. Works fine, except it opens the change pre approved. I need it to open a change with approval 'Not Yet Requested' or in other words not run through the attached Change workflow. Is there a way for me to do this? Below is my script.
(function(current, previous, gs, action) {
var changeRequest = ChangeRequest.newNormal();
changeRequest.setValue("type", "Normal");
changeRequest.setValue("category", "New Installation");
changeRequest.setValue("approval", "Not Yet Requested");
changeRequest.setValue("u_uatrequired", "No");
changeRequest.setValue("u_string_3", "No UAT applicable");
changeRequest.setValue("short_description", "New Server Deployed");
changeRequest.setValue("u_kb_article_number", "9e0869876fc2020063be9d4e5d3ee4b0");
changeRequest.setValue("u_system", current.variables.system);
changeRequest.setValue("assigned_to", current.assigned_to);
changeRequest.insert();
current.rfc = changeRequest.getGlideRecord().getUniqueValue();
current.update();
gs.addInfoMessage("Change " + changeRequest.getValue("number") + " created");
action.setRedirectURL(changeRequest.getGlideRecord());
action.setReturnURL(current);
})(current, previous, gs, action);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2017 10:07 AM
If it helps, this is the UI Action script I use to create a Change from a Catalog Task. (I have a field on the catalog task called "Change ID" which populates when the Change is created (so a task only correlates to one change).)
Condition: gs.hasRole("itil") && current.u_change_id.nil()
Script:
var change = new GlideRecord("change_request");
change.short_description = current.short_description;
change.description = current.description;
change.cmdb_ci = current.cmdb_ci;
change.priority = current.priority;
var sysID = change.insert();
current.u_change_id = sysID;
var mySysID = current.update();
gs.addInfoMessage("Change " + change.number + " created");
action.setRedirectURL(change);
action.setReturnURL(current);
Richelle

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 06:36 AM
When using setValue(), you need to use the value (from sys_choice). it appears you are using the label.
Try this:
changeRequest.setValue("approval", "not requested");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 06:41 AM
Thanks Chuck, but it looks like its still kicking off the workflow and now rejecting it because it doesn't have all the required fields.I'm looking for a way to open the change in a draft state.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 06:54 AM
Two things Danielle,
If you want to set it to a Draft state, then you'll need a setValue('state', value) in there somewhere. I didn't see one.
If you want to stop it from triggering the workflow immediately, use this before the insert().
changeRequest.setWorkflow(false);
Keep in mind this also disables any business rules on insert as well!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 07:09 AM
Chuck,
I added the two pieces you suggested and its still kicking off the workflow and moving to approved.