Business rule not aborting update

Abbottronix
Tera Guru

I'm trying to write a business rule that prevents an incident from being proposed as a major incident if the user lacks MIM roles, but it's not aborting the proposal. This is my condition and code:

 

Abbottronix_0-1732848437290.png

 

(function executeRule(current, previous /*null when async*/) {

	var user = gs.getUser();
	
	if (!user.hasRole('incident_manager') || !user.hasRole('major_incident_manager')) {
		gs.addErrorMessage('If you are proposing a Major Incident, you are required to engage the Major Incident Management (MIM) team by PHONE CALL.  Contact details and Escalation Matrix can be found in the Enterprise Service Management Policy and Procedures Manual (ESM PPM).');
		current.setAbortAction(true); 
	}


})(current, previous);

The error message is appearing, but the incident is still getting proposed as a MIM candidate. 

1 ACCEPTED SOLUTION

Sherin Jenifer
Giga Guru

Hi @Abbottronix , as @Runjay Patel  suggested the State will not be updated as Proposed as it will throw Invalid update error. The State Choice list changes to Proposed in the client-side alone, it is not updated in the server-side. If you could Reload form , you can find that the state is not updated.


If you find this helpful, please mark as Correct or Helpful.

View solution in original post

6 REPLIES 6

Since you are expecting a change to reflect on the client side, you should preferably go for a client script - OnChange type for the field Major incident state. Try this out

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    //Type appropriate comment here, and begin script below
    if (newValue == '2') {//Mention your major incident 'proposed' state value here
        if (!g_user.hasRoleExactly('incident_manager') && !g_user.hasRoleExactly('major_incident_manager')) {
			g_form.setValue('major_incident_state', oldValue); //mention your major incident state field name here
            g_form.addErrorMessage('If you are proposing a Major Incident, you are required to engage the Major Incident Management (MIM) team by PHONE CALL.  Contact details and Escalation Matrix can be found in the Enterprise Service Management Policy and Procedures Manual (ESM PPM).');
            
        }
    }
}

 


If you find this helpful, please mark as Correct or Helpful.

Thank you I'll give it a try