Want to capture the RISK SCORE from an assessment on the CHANGE RECORD

ChrisONeill
Mega Contributor

I have found alot of talk around this issue, but haven't found anything specific on this.   My group wants to have the result of the Risk Assessment (the raw score value) tracked on the CHANGE REQUEST so that they can do some statistical analysis on it over the long term.

 

My problem is that I can't find how to get to that Risk Score.   I can see within the Risk Calculator scripts where the system is running a query against the Risk Assessment, but I don't see anywhere where there is a way (other than that query model) to get that value from the completed Risk Assessment, and then populate it in the Change Request form.

 

Any assistance on this would be really helpful.   Thanks!

 

Chris O'Neill

CAI

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Chris,



I did some digging and it doesn't look like that score is actually captured anywhere. If you wanted it on your change request you could add a new field and then put something like this in a before update business rule. Adding to a new business rule let's you have this functionality without updating any OOB functionality.



var score = 0;


var srGR = new GlideRecord('survey_response');


srGR.addQuery('instance.task', current.sys_id);


srGR.addNotNullQuery('answer_integer');


srGR.query();


while (srGR.next()){


  score += srGR.answer_integer;


}


current.u_my_new_score_integer_field = score;



I grabbed most of that code from the calcCompositeScore() function in the RiskAssessmentCalculator script include.


View solution in original post

7 REPLIES 7

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Glad you got this working! Could you mark my answer correct if it worked for you?


Hi, thanks for this, this has helped me alot, but, the only problem I have is that its adding up all the scores from the assessment regardless of whether or not its related to the assessment on the problem record (we are using the risk assessment on Problem to calculate a Defect Risk)   A new risk assessment has been set up called Defect Prioritisation Calculation




I've got a business rule to run this.   I added in a check in the log, and the instance brings back all instances where a survey has been completed:




gs.log('im going to run the score');


gs.log('my current sys ID is - ' +current.sys_id);



var score = 0;  


var srGR = new GlideRecord('survey_response');  


srGR.addQuery('instance.task', current.sys_id);  


srGR.addNotNullQuery('answer_integer');  


srGR.query();  


while (srGR.next()){  


  gs.log('my answer interger is   - ' +srGR.answer_integer);


  gs.log('instance is     - ' +srGR.instance);


  score += srGR.answer_integer;    


}  


current.u_dpc = score;  


current.update();




When I try to manually get to the survey responses for a particular problem, I can not see instance.task in the list. ( I have attached a screen shot)




Any ideas how I get round this so I only get the scores related to the current problem record?




Any help is appreciated




Thank you






Michael Kaufman
Giga Guru

Note for future adventurers.  If you are using the new assessment functionality...I couldn't get the risk_value to calculate anymore.  Maybe there is a secret sys_properties to enable that.

I added this code to the "Calculate Risk" UI action to calculate the risk value.  There are probably better ways to do this of course, but this worked for me.

//Calculate Risk Value
var score = 0;
var gr = new GlideRecord('asmt_assessment_instance_question');
gr.addQuery('instance.task_id', current.sys_id);
gr.query();
while (gr.next()){
score += parseInt(gr.getValue('value'));
}
current.risk_value = score;
current.update();