Risk Condition based on the answer to a Risk Assessment question

dannybowers
Kilo Contributor

Hi,

Fairly new to SN development so apologies if I'm missing something obvious. I'm wondering if it is possible to use the answer to a Risk Assessment question as the basis for a Risk Condition?

What we have is a Risk Assessment used in our change process containing 15 questions. Each question has 3 answers and each answer is assigned a score of 0, 1 or 2. The total score of the 15 questions is used to calculate the Risk score given to the Change.

What I'd like to do is to add a Risk Condition that references the answer to a specific question from the Risk Assessment and then adjusts the Impact rating of the change. The reason being is that certain answers to certain questions would always mean a Change being taken to a CAB meeting irrespective of what the Risk is calculated out at, and we use the Impact in order to do that.

An example would be, someone answers 14/15 questions with the lowest possible score and 1 question is answered with the highest score. The overall calculation means the total score falls below the threshold and the Change is given a low Risk score. However, because of that one answer, I want to make the Impact adjust up a level.

Essentially I think I need a piece of code that references back to the answers given in the Risk Assessment and I'm not sure what that would look like.

Hope that makes sense.


Cheers

1 ACCEPTED SOLUTION

Chris Chambers1
Mega Guru

Hi Danny,


I have mocked this up in a DEV and I am able to get the desired result. I did this on an Istanbul instance, and found a log entry:



{"error":{"detail":"Record doesn't exist or ACL restricts the record retrieval","message":"No Record found"},"status":"failure"}



So make sure you investigate exactly what this means to your Change Request record.



That said, this is what you need in a Risk Condition:



Use Advanced Condition = true



Use Script values = true



Order = you may want to set this highest, relative to other risk conditions



Advanced condition:


//Set the variable 'answer' to true to indicate that this risk condition matches, and false if it does not match the change request. You need to set this to your condition. it might be that you want it to run everytime, in which case, answer=true is fine


answer = true;



Script Values:


//you have access to current, being the Change Request record


if (checkRAResult(current.sys_id.toString())){



  if (current.impact != '1'){


  //raise Impact by one. Fine if Risk Conditions run manually, but if automated, set it as a hard value, else it will always end up as 1!


    current.impact = current.impact - 1;


  }


}


function checkRAResult(current){


  var result = false;


  //Check the task_assessment table for a record that matches this (current) Change record


  var gr_task_assessment = new GlideRecord("task_assessment");


  gr_task_assessment.addQuery("task", current);


  gr_task_assessment.query();



  //if we find a match, get the questions/responses for the assessment


  if (gr_task_assessment.next()) {


  var gr_survey_response = new GlideRecord("survey_response");



  //instance is the sys_id of the task_assessment


  gr_survey_response.addQuery("instance", gr_task_assessment.instance);



  //get hold of the question we are interested in


  gr_survey_response.addQuery("question.question_text", "How easy is it for the implementer to verify that the change was completed successfully?");


  gr_survey_response.query();



  //if we find a response


  if (gr_survey_response.next()) {


  //check if the response is the value we want to check


  if (gr_survey_response.response == "Medium"){


  result = true;


  // Set the Risk/Impact using the fields above, or its possible to script them by checking the "Use Script Values" checkbox. this means, you can set any field to the value of your choice, if this Condition script sets answer = true.


  }


  else {


  result = false;


  }


  }


  }


  return result;


}



RiskCondition1.PNG



Hope this helps!


Chris.


View solution in original post

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Danny,



I've been able to do thing like this in the past by using much higher numbers for the third option. Sometimes it takes some creative math, but if you made the scores 0,1, or 15 then you would cross your threshold whenever someone picks the third option. I would see what you can do on that front before trying to hack up the scoring.


Hi Brad,



Thanks for the reply. I had considered that, but it doesn't quite meet our requirements unfortunately. It's not the Risk score I want to jump up, it's the Impact as it could justifiably be a low Risk change but just with high Impact (e.g. due to time performed or outage required).



Cheers


Chris Chambers1
Mega Guru

Hi Danny,


I have mocked this up in a DEV and I am able to get the desired result. I did this on an Istanbul instance, and found a log entry:



{"error":{"detail":"Record doesn't exist or ACL restricts the record retrieval","message":"No Record found"},"status":"failure"}



So make sure you investigate exactly what this means to your Change Request record.



That said, this is what you need in a Risk Condition:



Use Advanced Condition = true



Use Script values = true



Order = you may want to set this highest, relative to other risk conditions



Advanced condition:


//Set the variable 'answer' to true to indicate that this risk condition matches, and false if it does not match the change request. You need to set this to your condition. it might be that you want it to run everytime, in which case, answer=true is fine


answer = true;



Script Values:


//you have access to current, being the Change Request record


if (checkRAResult(current.sys_id.toString())){



  if (current.impact != '1'){


  //raise Impact by one. Fine if Risk Conditions run manually, but if automated, set it as a hard value, else it will always end up as 1!


    current.impact = current.impact - 1;


  }


}


function checkRAResult(current){


  var result = false;


  //Check the task_assessment table for a record that matches this (current) Change record


  var gr_task_assessment = new GlideRecord("task_assessment");


  gr_task_assessment.addQuery("task", current);


  gr_task_assessment.query();



  //if we find a match, get the questions/responses for the assessment


  if (gr_task_assessment.next()) {


  var gr_survey_response = new GlideRecord("survey_response");



  //instance is the sys_id of the task_assessment


  gr_survey_response.addQuery("instance", gr_task_assessment.instance);



  //get hold of the question we are interested in


  gr_survey_response.addQuery("question.question_text", "How easy is it for the implementer to verify that the change was completed successfully?");


  gr_survey_response.query();



  //if we find a response


  if (gr_survey_response.next()) {


  //check if the response is the value we want to check


  if (gr_survey_response.response == "Medium"){


  result = true;


  // Set the Risk/Impact using the fields above, or its possible to script them by checking the "Use Script Values" checkbox. this means, you can set any field to the value of your choice, if this Condition script sets answer = true.


  }


  else {


  result = false;


  }


  }


  }


  return result;


}



RiskCondition1.PNG



Hope this helps!


Chris.


Just starting to test in Dev Chris, but this looks to have done the job mate.



Thanks so much, hugely appreciated!



Danny