I want to enable a business rule that prevents a case from closing if there are still open tasks attached to the case. I have created the business rule but it seems there is another business rule that is overriding mine. Could you please assist.

Tshwarelo1
Kilo Contributor

I want to enable a business rule that prevents a case from closing if there are still open tasks attached to the case. I have created the business rule but it seems there is another business rule that is overriding mine. Could you please assist.

5 REPLIES 5

Community Alums
Not applicable

HI @Tshwarelo ,

This is the Business rule which does the job:

find_real_file.png

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

 

 

 

Tshwarelo1
Kilo Contributor

Hi Sandeep

Thank you, I have enabled this business rule on my instance and disabled the one I created. However I am still able to close a parent case with HR tasks still open. They all move to closed Incomplete.

Hi @Tshwarelo 

I usually create a client script (since cannot change State via list) and script include to accomplish this.  Here's an example, but please take into account if translations are needed for the alert or message that appears.  This example does not.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}

	if(newValue==3) { //Closed Complete
		var ga = new GlideAjax('ICHRScriptInclude');
		ga.addParam('sysparm_name', 'validateChildTasks');
		ga.addParam('sys_id', g_form.getUniqueValue());
		ga.getXML(setValues);
	}
        
	function setValues(response) {
		var answer = response.responseXML.documentElement.getAttribute('answer');
		if(answer == "true") {
			alert("Please complete all of the child tasks before closing this case.");
			g_form.setValue('state',oldValue);
		} else {
			g_form.setValue('state',newValue);
		}
	}
}

 

validateChildTasks: function(){
		var sys_id = this.getParameter('sys_id');
		var flag = false;
		var taskRec = new GlideRecord('task');
		taskRec.addQuery('parent', sys_id);
		taskRec.addActiveQuery();
		taskRec.query();
		while (taskRec.next()) {
			flag = true;
		}
		return flag;
	},

Tshwarelo1
Kilo Contributor
Hi @sbritt I am clearly doing something wrong, tried the above with no luck, let me reach out to HI support. Thank you all for the assistance!