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

Hi Danielle,



It sounds like there may be other bits at work here. Without hands on keyboard and eyes on screen, this is going to be tough to debug from the community. If nobody else here has any ideas, try reaching out to customer support. I'd be curious to know what they have to say.



HI Service Portal - ServiceNow


Contact Support | ServiceNow


Thanks for assisting. I will open a ticket with HI.


HI Chuck,



I spoke with HI and they offered a little assistance but advised they don't normally assist with scripts. We were able to stop the workflow from kicking off by change line "var changeRequest = ChangeRequest.newNormal();" to "var changeRequest = new GlideRecord('change_request');" but now the UI Action doesn't automatically take you to the change form like it had before. Any thoughts on how to fix this?



Thanks!


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


That works!! Thank you for the help!