Capture Risk Assessment answers and put them into the change work notes?

Conan_Lloyd
Mega Expert

Apparently out compliance folk are not happy that our risk assessments do not version if they are retaken. A solution was proposed to capture the answers when it's taken and add them to the work notes of the change its attached to. Can a kind soul out there help me with the script to do this?

~Conan

1 ACCEPTED SOLUTION

Towards the bottom is how you get the score. The top bit is how you can get answers to specific questions.

Writing a Risk Assessment Answer Back to Change Form Field


View solution in original post

10 REPLIES 10

sekhar kurumoju
Mega Guru

 

Capture Risk Assessment answers and put them into the change work notes?

Yes We Can Do that different way. Here i am get "

 answers" Description Filed 

 

Here I Using Background Script to get user response and i am get the Question and Respective user answer i am captured and where i want place that values. "Metric Results"(asmt_metric_result) always stored in this table.

 I am Getting Risk Assessment answers using Script include:

var Risk = Class.create();
Risk.prototype = {
    initialize: function() {},
    testAnswer: function(sys_id) {
        var varAnswer = [];
        var gr = new GlideRecord("asmt_metric_result");
        gr.addQuery("metric.category.nameSTARTSWITHchange^source_id=" + sys_id);
		gr.orderBy("metric.order");
        gr.query();
        while(gr.next()) {
           varAnswer.push(gr.string_value.toString());

        }
        return varAnswer;
    },
    testQuestion: function(sys_id) {
        var varQuestion = [];
        var gr = new GlideRecord("asmt_metric_result");
        gr.addQuery("metric.category.nameSTARTSWITHchange^source_id=" + sys_id);
		gr.orderBy("metric.order");
        gr.query();
        while (gr.next()) {
            varQuestion.push(gr.metric.question.toString());

        }
        return varQuestion;
    },
    type: 'Risk'


};

and i am Creating One Business Rule On "Metric Results"(asmt_metric_result) table with Async Rlue and i am Displaying User Response on "Change Table"(change_request) in  Description Filed if you can filed

Business Rule :

(function executeRule(current, previous /*null when async*/ ) {
    var grChg = new GlideRecord("change_request");
    grChg.addQuery("sys_id", current.source_id);
    var answer = new Risk().testAnswer(current.source_id);
    answer.split(",");
    var question = new Risk().testQuestion(current.source_id);
    question.split(",");
    grChg.query();
    if (grChg.next()) {
        grChg.description ="**********************USER RESOPNES*******************" + "\n" +
            "Question.1 :" + question[0] + "\n" + "Answer :" + answer[0] + "\n" +
            "Question.2 :" + question[1] + "\n" + "Answer :" + answer[1] + "\n" +
            "Question.3 :" + question[2] + "\n" + "Answer :" + answer[2] + "\n" +
            "Question.4 :" + question[3] + "\n" + "Answer :" + answer[3] + "\n" +
            "Question.5 :" + question[4] + "\n" + "Answer :" + answer[4];
    }
    grChg.update();

})(current, previous);

find_real_file.pngsame code you  check  Background-Script as well .I will Give that Working Code Placed  here you can try it :

Background Script :

var answer = new Risk().testAnswer("fc673e932f94a810f7674ae72799b6f9")//Risk Assessment Completed  Change Request sys_id
answer.split(",");
var question = new Risk().testQuestion("fc673e932f94a810f7674ae72799b6f9")//Risk Assessment Completed  Change Request sys_id
question.split(",");

      var gr = new GlideRecord("asmt_metric_result");
      gr.addQuery("metric.category.nameSTARTSWITHchange^source_id=fc673e932f94a810f7674ae72799b6f9");//Risk Assessment Completed  Change Request sys_id
      gr.query();
           if(gr.next()){
                var grChg= new GlideRecord("change_request");
                grChg.addQuery("sys_id",gr.source_id);
                grChg.query();
                   if(grChg.next()){
              grChg.description="Question.1 :"+question[0]+"\n"+"Answer :"+ answer[0]+"\n"+
          "Question.2 :"+question[1]+"\n"+"Answer :"+ answer[1]+"\n"+
           "Question.3 :"+question[2]+"\n"+"Answer :"+ answer[2]+"\n"+
           "Question.4 :"+question[3]+"\n"+"Answer :"+ answer[3]+"\n"+
            "Question.5 :"+question[4]+"\n"+"Answer :"+ answer[4];
                 }
           grChg.update();
              
}
 

 

Result:

find_real_file.png