How to make Risk Assessment Mandatory on Change Request, before submitting for approval

Baggies
Kilo Guru

I am trying to force users to complete a risk assessment on Change Request, before it can go for Approval.

I would like to use the functionality from the 'Calculate Risk' UI Action, which checks for a completed Risk Assessment. If one hasn't been done, the Info Message 'Complete Risk Assessment to calculate risk'  is displayed. This UI Action has the condition "&& new ChangeRiskAsmt().showRiskCalculation(current)" which I thought I may be able to leverage.

I have read a few suggestions about adding script to the UI Action, but I have failed miserably. Here is one for example:

https://community.servicenow.com/community?id=community_question&sys_id=3444cb29dbd8dbc01dcaf3231f96....

has anyone found a way to force a risk assessment to be done before it going for Approval? I really don't want to do it on a client script either.

Many thanks,

Mark S

 

 

 

1 ACCEPTED SOLUTION

Narendra Kota
Mega Sage

You can write a business rule.

Table: change_request

when to run: before update

condition: state changes to // give state value here, like awaiting approval etc.

var assessmentinstance = new GlideRecord ('asmt_assessment_instance'); 
assessmentinstance.addQuery('task_id', current.sys_id);
assessmentinstance.query();
if(!assessmentinstance.next())
	{
	current.setAbortAction(true);
	gs.addInfoMessage('Please perform risk assesment before requesting for approval');
	current.state = 1; //check state value
	current.approval = 'not requested'; //remove it if you don't want to set approval
		
}

find_real_file.png

 

Hope this helps.
Mark helpful or correct based on impact.

Thanks.

View solution in original post

8 REPLIES 8

Narendra Kota
Mega Sage

You can write a business rule.

Table: change_request

when to run: before update

condition: state changes to // give state value here, like awaiting approval etc.

var assessmentinstance = new GlideRecord ('asmt_assessment_instance'); 
assessmentinstance.addQuery('task_id', current.sys_id);
assessmentinstance.query();
if(!assessmentinstance.next())
	{
	current.setAbortAction(true);
	gs.addInfoMessage('Please perform risk assesment before requesting for approval');
	current.state = 1; //check state value
	current.approval = 'not requested'; //remove it if you don't want to set approval
		
}

find_real_file.png

 

Hope this helps.
Mark helpful or correct based on impact.

Thanks.

Hello, and many thanks for the reply. A little fine tuning, and this seems to work fine ..so far. I ended up with this:

Table: change_request
when to run: before update
condition: current.state.changesTo(-4)

 

Using the latest State management model, -5 is New, and -4 is Assess

 

var assessmentinstance = new GlideRecord('asmt_assessment_instance');
assessmentinstance.addQuery('task_id', current.sys_id);
assessmentinstance.query();
if (!assessmentinstance.next()) {

    current.setAbortAction(true);

    gs.addInfoMessage('Please perform risk assesment before requesting for approval');
    current.state = -5; //check state value return to New
    current.approval = 'not requested'; //remove it if you don't want to set approval

}(current, previous);


 

 

I attempted this and it still allowed it to move to Assess.  Can you tell me where I went wrong?

find_real_file.png

find_real_file.png

Not sure what state you have in your condition. For me, the value of -4 is 'Assess", so when the state changes to Assess, value of -4, the BR will kick off. You have (2) in your BR condition.

My final script is below, and it is working fine.

Business rule:

Table: change_request
when to run: before update
condition: current.state.changesTo(-4)

 

(function executeRule(current, previous /*null when async*/ ) {
    var assessmentinstance = new GlideRecord('asmt_assessment_instance');
    assessmentinstance.addQuery('task_id', current.sys_id);
    assessmentinstance.query();
    if (!assessmentinstance.next()) {

        current.setAbortAction(true);

        gs.addInfoMessage('Please perform risk assesment before requesting for approval');
        current.state = -5; //check state value
        current.approval = 'not requested'; //remove it if you don't want to set approval
    }
})(current, previous);