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

Aditya Mallik
ServiceNow Employee
ServiceNow Employee

The script include "ChangeRequest" extends from "ChangeRequestSNC". While "ChangeRequestSNC" is protected from updates, you can modify the code in "ChangeRequest" script include. You can add the function for the new Change Type in "ChangeRequest" script include.


Hi Aditya



How... like this? (new lines marked with bold).. Tried it, but then it doesn'tn add the workflow...



var ChangeRequest = Class.create();


     


ChangeRequest.NORMAL = "normal";


ChangeRequest.STANDARD = "standard";


ChangeRequest.EMERGENCY = "emergency";


ChangeRequest.CHANGE_REQUEST = "change_request";


ChangeRequest.INFRASTRUCTURE_SERVER = "infrastructure_server";



ChangeRequest.prototype = Object.extendsObject(ChangeRequestSNC, {


      type: "ChangeRequest"


});



ChangeRequest.newInfrastructure_Server = function() {


  return ChangeRequestSNC.newChange(ChangeRequest.INFRASTRUCTURE_SERVER);


};


ChangeRequest.newNormal = ChangeRequestSNC.newNormal;


ChangeRequest.newStandard = ChangeRequestSNC.newStandard;


ChangeRequest.newEmergency = ChangeRequestSNC.newEmergency;


ChangeRequest.newChange = ChangeRequestSNC.newChange;


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.


Hi Aditya



Your answer about that the script include "ChangeRequest" extends from "ChangeRequestSNC" was 100% correct!



I was using capital-letters and not small letters.


It should we written in the same way as in the script include "ChangeRequestStateHandler".




ChangeRequestStateHandler.prototype = Object.extendsObject(ChangeRequestStateHandlerSNC, {


  INFRASTRUCTURE_SERVER:"infrastructure_server",



Thanks


Soeren!