Adding a new change type and using it when creating change from incident

priisholm
Mega Expert

Hi guys!

We added a few new change types using this guideline: Add a new change type

This works just fine until we want to create a change from an incident.

I would like to make a new UI action for each new change type (so it can be used/clicked from the "form context menu") using the (OOB) script from "Create Normal Change" - lets call this new change-type : Infrastructure_server. The only difference between Normal-change and Infrastructure_server-change is the workflow behind. So same fields on the change-form etc.

(function(current, previous, gs, action) {

  var changeRequest = ChangeRequest.newNormal();

  changeRequest.setValue("short_description", current.short_description);

  changeRequest.setValue("description", current.description);

  changeRequest.setValue("cmdb_ci", current.cmdb_ci);

  changeRequest.setValue("priority", current.priority);

  changeRequest.setValue("sys_domain", current.sys_domain);

  changeRequest.setValue("company", current.company);

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

---

The problem is this line...where ServiceNow (Helsinki) create a new object using "newNormal()".

  var changeRequest = ChangeRequest.newNormal();

I want to make something like this..:

  var changeRequest = ChangeRequest.newInfrastructure_server();

When I look into the "script includes" the script "ChangeRequestSNC" is the only place where "newNormal()" is defined by this lines (302-304):

ChangeRequestSNC.newNormal = function() {

  return ChangeRequestSNC.newChange(ChangeRequest.NORMAL);

};

...but this script include is read-only...

So how could I add a new change-type to the "create change functionality from incidents" ?

Thanks!

Soeren

1 ACCEPTED SOLUTION

Hi,



Did you go through the link Add a new change type that explains how to add your own Change Type. You need to ensure that you create a Workflow and specify the condition in the Workflow appropriately so that it gets attached to the Change_Request records when type = INFRASTRUCTURE_SERVER.



Refer to step 6 "Create a workflow for the new change request type." in the link Add a new change type.



Thanks.


View solution in original post

10 REPLIES 10

Hi all,



In the end I decided to create a new change request glide record, and set the change type myself. Please see code below.


function(current, previous, gs, action) {


  var changeRequest = new GlideRecord('change_request');


  changeRequest.initialize();


  changeRequest.setValue("short_description", current.short_description);


  changeRequest.setValue("description", current.description);


  changeRequest.setValue("cmdb_ci", current.cmdb_ci);


  changeRequest.setValue("priority", current.priority);


  changeRequest.setValue("sys_domain", current.sys_domain);


  changeRequest.setValue("company", current.company);


  changeRequest.setValue("type", 'expedited');


  current.rfc = changeRequest.insert();



  current.update();



  gs.addInfoMessage("Change " + changeRequest.getValue("number") + " created");


  action.setRedirectURL(changeRequest);


  action.setReturnURL(current);



})(current, previous, gs, action);



I hope it helps! Any feedback is welcome



Cheers,


Robert