How could you get the risk assessment to calculate automatically?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2014 08:59 AM
How would you get the risk assessment calculate on a change request to populate as soon as you click submit on the assessment so you don't then need to click the UI action to calculate?
I tried piecing both the UI actions together (see below) but it's not performing the calculation. It saves the risk assessment but that's it.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2015 08:43 AM
Geek: did you finally manage to get both UI Actions to execute one after the other one?
I'm trying to achieve the same result. I want the Calculate Risk UI Action to execute immediately after the Risk Assessment UI Action, but I'm facing the same problems. I can't get to combine both in the same UI Action and when I activate the Business Rule instead, then the Business Rule keep updating the value at every update, which is not what we want. We would like to let the user be able to modify it by hand even if the system plugs in a default value based on calculation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2015 11:51 AM
write an after insert and update BR on survey response table
condition = current.instance.survey.name == 'Change Risk Assesment';
var gR = new GlideRecord('survey_response');
gR.addQuery('instance',current.instance);
gR.query();
//If all the survey for the current instance has been created, calculate risk
if(gR.getRowCount() == gs.getProperty('change_num_risk_questions')){
//If no records inserted is equal to no of questions
//Get the assessment record
var gR1 = new GlideRecord('task_assessment');
gR1.addQuery('instance',current.instance);
gR1.query();
if(gR1.next()){
//Get the assessment change record
var chg = gR1.task.getRefRecord();
var scr = new RiskAssessmentCalculator();
var assessmentMatch = scr.checkForMatchingAssessment(chg.sys_class_name, chg);
if (assessmentMatch == '') {
calcRisk(chg);
}
else {
var takenRA = scr.checkForAssessmentInstance(chg.sys_id);
//the correct assessment has been taken
if (takenRA != '' && takenRA == assessmentMatch){
calcRisk(chg);
}
if (takenRA != '' && takenRA != assessmentMatch){
gs.addInfoMessage(gs.getMessage('Incorrect risk assessment taken, please fill out a new assessment'));
chg.setAbortAction(true);
}
if (takenRA == ''){
gs.addInfoMessage(gs.getMessage('A risk assessment is required, please fill out a risk assessment'));
chg.setAbortAction(true);
}
}
}
}
//Calculate the risk for the instance
function calcRisk(change) {
var risk = scr.calculateRisk(change);
chg.update();
}
try this code hope it helps you
Thanks
Vijay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2015 02:58 PM
Vijay,
This was a useful script. I modified it to count the questions in the change assessment, instead of relying on a system property.
var survey = new GlideRecord('survey_response');
survey.addQuery('instance',current.instance);
survey.query();
//If all the survey responses for the current instance have been created, calculate the risk
if (survey.getRowCount() == countQuestions(current.instance.survey)) {
//If the number of records inserted is equal to the number of questions, get the assessment record
var asmnt = new GlideRecord('task_assessment');
asmnt.addQuery('instance',current.instance);
asmnt.query();
if(asmnt.next()){
//Get the assessment change record
var chg = asmnt.task.getRefRecord();
var calc = new RiskAssessmentCalculator();
var assessmentMatch = calc.checkForMatchingAssessment(chg.sys_class_name, chg);
if (assessmentMatch == '') {
calcRisk(chg);
}
else {
var takenRA = calc.checkForAssessmentInstance(chg.sys_id);
//the correct assessment has been taken
if (takenRA != '' && takenRA == assessmentMatch){
calcRisk(chg);
}
if (takenRA != '' && takenRA != assessmentMatch){
gs.addInfoMessage(gs.getMessage('Incorrect risk assessment taken, please fill out a new assessment'));
chg.setAbortAction(true);
}
if (takenRA == ''){
gs.addInfoMessage(gs.getMessage('A risk assessment is required, please fill out a risk assessment'));
chg.setAbortAction(true);
}
}
}
}
//Calculate the risk for the instance
function calcRisk(change) {
var risk = calc.calculateRisk(change);
chg.u_has_assessment = true;
chg.update();
}
//Count the number of assessment questions
function countQuestions(survey) {
var questions = new GlideRecord('assessment_question');
questions.addQuery('master', survey);
questions.addQuery('weight', '>', '0');
questions.query();
if (questions.hasNext()) {
return questions.getRowCount();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2016 08:53 AM
Thanks to Vijay and John for this.
Small cautionary tale, so you can learn from my mistakes. I thought I'd try a simpler way around. My idea was to run the rule on the Task Assessment table, which links the survey to the change ticket, rather than the Survey Response table as suggested. I thought as soon as the fully formed Task Assessment record appeared, then the whole survey would be up for grabs. Turns out you can't do that. The survey responses get inserted after the task assessment record, so waiting for all the question responses to turn up, then fishing for the task assessment record is the way to go.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2016 03:41 AM
The Business Rule is good, but the calculation happens quietly in the background. The user still has to reload the form to see the benefit of it. I wanted to force a screen refresh shortly after the Risk Assessment was filled in. I managed it like so:
- Added a flag (true/false field) called u_assessment_called to the Change form.
- Added a line of code to the UI Action which calls the Risk Assessment field. It ticks the above flag when the Save button is pressed
- Added a Client Script to Change which looks out for this flag being set. It waits a second, clears the flag, and submits the form, i.e. forces a page refresh. This causes the Risk messages to be displayed at the top of the screen.
In the UI Action called Fill Out Risk Assessment, the code to set the flag code goes just after view.mandatoryResult
if (eventObj.view.mandatoryResult) { | |||||||
g_form.setValue('u_assessment_called','true'); | |||||||
d.close(); | |||||||
} |
The Client Script is an onChange one, running on Change Request, acting on the Assessment Called field. The script looks like this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
// When the Assessment Called box gets ticked, which should happen
// after the Risk Assessment has been done,
// wait a second and reload.
if (newValue == 'true')
{
setTimeout( function(){
g_form.setValue("u_assessment_called", false);
g_form.save(); }, 1000);
}
}
It seemed waiting for a second was safest bet with all the server side code happening in the Business Rule.