Help with Business Rule: cannot resolve Incident if it has open checklist items

JP-ODU
Tera Guru

I already have a functional biz rule running to prevent resolution when our incidents have open incident tasks:

(function executeRule(current, previous /*null when async*/) {
        incitask=new GlideRecord('incident_task');
		incitask.addQuery('parent',current.sys_id);
		incitask.addQuery('state','!=','3'); //Closed complete
		incitask.addQuery('state','!=','4'); //Closed incomplete
		incitask.addQuery('state','!=','7'); //Closed skipped
		incitask.query();
		if(incitask.next())
			{
				gs.addErrorMessage('Incident cannot be closed as Incident child task is still open');
				current.setAbortAction(true);
			}
	
})(current, previous);	

 And I was given a new requirement, to also prevent resolution of incidents with open items in their checklist. So I mocked up this:

(function executeRule(current, previous /*null when async*/) {
    ci = new GlideRecord('checklist_item');
    ci.addQuery('checklist.document', g_form.getUniqueValue());
    ci.addQuery('complete', false);
    ci.query();
    if (ci.next()) {
			gs.addErrorMessage('Incident cannot be closed as one or more checklist item(s) remain open');
			current.setAbortAction(true);
    }
})(current, previous);

This attempt isn't working, neither scripted into the same rule checking for incident tasks nor running as it's own biz rule (order 2). Does anyone see what's wrong with it?

1 ACCEPTED SOLUTION

Ravi Peddineni
Kilo Sage

@JP-ODU 

 

You are using g_form.getUniqueValue() in a business rule which is causing the issue.

g_form.getUniqueValue()

 

You should be using current.getUniqueValue()

View solution in original post

2 REPLIES 2

Ravi Peddineni
Kilo Sage

@JP-ODU 

 

You are using g_form.getUniqueValue() in a business rule which is causing the issue.

g_form.getUniqueValue()

 

You should be using current.getUniqueValue()

Perfect, it's fixed. Thank you!