Adding New Change Type

Brian Lancaster
Tera Sage

I followed this document to add a new change type.  However it does not go over how to update the ChangeRequest script include so you can create a change request of this new type thought a UI Action.  How do I go updating the script include?

17 REPLIES 17

what does your UI action look like?

 

(function(current, previous, gs, action) {
	var changeRequest = ChangeRequest.newExpedite();
	changeRequest.setValue("short_description", current.short_description);
	changeRequest.setValue("description", current.description);
	changeRequest.setValue("cmdb_ci", current.cmdb_ci);
	if (changeRequest.hasValidChoice('priority', current.priority))
		changeRequest.setValue("priority", current.priority);
	changeRequest.setValue("sys_domain", current.sys_domain);
	changeRequest.setValue("company", current.company);
	changeRequest.setValue("u_parent_ticket", current.sys_id);
	changeRequest.insert();

	current.u_rfc = changeRequest.getGlideRecord().getUniqueValue();
	current.update();
	var incUrl = "<a href='" + current.getLink(true) + "'>" + current.getDisplayValue() + "</a>";
	gs.addInfoMessage(gs.getMessage("Expedite Change {0} created from {1}", [changeRequest.getValue("number"), incUrl]));
	action.setRedirectURL(changeRequest.getGlideRecord());
	action.setReturnURL(current);

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

I looked at my UI actions and they have a few extra lines at the top. They look like this:

(function(current, previous, gs, action) {
var target = {};
target.table = current.getTableName();
target.sysid = current.getUniqueValue();
target.field = 'rfc';
try {
target.isWorkspace = (typeof RP == 'undefined');
}
catch (err) {
target.isWorkspace = false;
}

gs.getSession().putProperty('change_link', target);

var changeRequest = ChangeRequest.newNormal();
changeRequest.setValue("short_description", current.short_description);
changeRequest.setValue("description", current.description);
changeRequest.setValue("cmdb_ci", current.cmdb_ci);
if (changeRequest.hasValidChoice('priority', current.priority))
changeRequest.setValue("priority", current.priority);
changeRequest.setValue("sys_domain", current.sys_domain);
changeRequest.setValue("company", current.company);
changeRequest.insert();

action.setReturnURL(current);
action.setRedirectURL(changeRequest.getGlideRecord());

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

Thanks for all your help.  I have another Post out there if you have any thought on that one.

https://community.servicenow.com/community?id=community_question&sys_id=fe297b86db954cd4f7fca851ca96...

Sorry this created a Normal change