Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Create Change UI Action from a Task

daniellethomson
Tera Expert

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);

1 ACCEPTED SOLUTION

richelle_pivec
Mega Guru

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


View solution in original post

9 REPLIES 9

Chuck Tomasi
Tera Patron

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");


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.


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!


Chuck,



I added the two pieces you suggested and its still kicking off the workflow and moving to approved.