Business Rule to Set a Standard Change Template Inactive after Change is Closed Incomplete

Mark Sandner
Kilo Contributor

I have a requirement. If a Standard Change Request fails, or is closed incomplete, I need to set the corresponding Standard Change Template (or Item) to Inactive so it cannot be used again until it has been reviewed.

I have a background script to query the Template, but how can I utilize this in a BR?

var gr = new GlideRecord('change_request');
gr.addEncodedQuery('std_change_producer_version.std_change_producer.active=true');
var template = gr.std_change_producer_version.std_change_producer.name;
gr.query();
while(gr.next()){

gs.print(gr.std_change_producer_version.std_change_producer.name);
}

 

Many thanks.

 

2 REPLIES 2

Sukhbir Singh2
Giga Guru

Hi use the below code in before update Business rule on  change_request table

condition should be - state changes to close incomplete

 

var std_change_producer_version = current.getValue("std_change_producer_version");
//gs.print(getStandardProducerVersion(std_change_producer_version));

var std_change_producer = getStandardProducerVersion(std_change_producer_version);

var std_change_producerGr = getStdRecProducer(std_change_producer);

if(std_change_producerGr.isValid()){
	// Deactivate standard record producer
	std_change_producerGr.active = true;
	std_change_producerGr.update();
	
	
	// Deactivate std change template
	var templateGr = new GlideRecord("std_change_template");
	templateGr.addQuery("short_description",''+std_change_producerGr.name);	
	templateGr.query();
	while(templateGr._next()){
		templateGr.active = true;
		templateGr.update();
	}	
}

function getStandardProducerVersion(std_change_producer_version){
var gr = new GlideRecord("std_change_producer_version");
gr.get(std_change_producer_version);
return gr.getValue("std_change_producer");
}


function getStdRecProducer(std_change_producer){
	var gr = new GlideRecord("std_change_record_producer");
	gr.get(std_change_producer);
	return gr;
}



 

Please mark my response correct/helpful, if it helped.

Thanks

 

Many thanks for your reply. I did try this in two different instances. There is no 'state' of 'close incomplete' on the change record form. So I had to substitute this for when the 'Close Code' changes to 'Unsuccessful'. I am not sure what the intended  script is doing, it is assuming the short description of the Change Request  is the same as the standard template name.
The BR runs, but does nothing, even when I remove the comments on the gs.print, there are no log entries, even if I add alerts, nothing happens. Did you manage to test this?

Thanks