- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2020 04:28 PM
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:
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2020 10:01 PM
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
}
Hope this helps.
Mark helpful or correct based on impact.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2020 10:01 PM
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
}
Hope this helps.
Mark helpful or correct based on impact.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2020 11:09 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2020 11:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2020 08:13 PM
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);