Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Jon G Lind
ServiceNow Employee
ServiceNow Employee

In the initial version of ReleaseOps a Deployment Request may end up in a terminal state such as Cancelled or Failed with no way to recover and start the process over.  The workaround to solve this is to run the following script in Scripts - Background or create a UI Action like a form link on the Deployment Request form in the ReleaseOps scope.

 

NOTE: If running from a background script eliminate the first line and replace the second with something like:

const drSysId = '{sys_id_here}';

 

(function(){  
	action.setRedirectURL(current);
	const drSysId = current.sys_id;

	const dr = new GlideRecord("sn_releaseops_deployment_request");
	dr.get(drSysId);
	gs.info("Cancelling DR " + dr.number + " " + dr.short_description);
	
	const pdc = new GlideRecord("sys_pd_context");
	pdc.addQuery("input_record", drSysId);
	pdc.query();

	while(pdc.next()){
		gs.info("Cancelling PD Context: " + pdc.getUniqueValue());
		sn_playbook.PlaybookExperience.cancelPlaybook(pdc, "Resetting due to error");
	}

	gs.info("Update DR State");
	dr.setWorkflow(false);
	dr.state = ReleaseOpsConstants.DEPLOYMENT_REQUEST_STATES.DRAFT;
	dr.update();
	gs.addInfoMessage("Cancelled any running playbooks and set state back to Draft.");
})();