1 Reply · Latest reply on May 21, 2017 12:56 PM by Laurent Chicoine

    On Change Requests, users want to retrieve previous completed Risk Assessments, instead of starting from scratch each time.

      Our Risk Assessment for Change Orders has 5 Yes / No questions:

      The user answers the 5 questions, that answers then determine the risk assessment.

       

      At a later time, the user wants to redo their risk assessment. However it restarts from the beginning each time.

      Is it possible that once a Risk Assessment has been submitted, and the Risk level determined, can the user then redo the risk assessment,

      but have it display their original answers they filled in on the 1st assessment, and not start from scratch each time?

       


      Thank You

      BOB S

        • Re: On Change Requests, users want to retrieve previous completed Risk Assessments, instead of starting from scratch each time.
          Laurent Chicoine

          Hi Robert,

           

          Here is how you can do it.

           

          1. Create the following script include

           

              Name: CustomTaskAssessmentUtil

              Client callable: false

              Script:

          var CustomTaskAssessmentUtil = Class.create();
          CustomTaskAssessmentUtil.prototype = {
              initialize: function() {
              },
              
              getExistingValue: function(taskAssessmentId, questionId){
                  if(!taskAssessmentId || !questionId){
                      return '';
                  }
                  
                  //Get the task assessment to retrieve the response from the survey instance
                  var taskAssessment = new GlideRecord('task_assessment');
                  if(taskAssessment.get(taskAssessmentId)){
                      var questionAnswer = new GlideRecord('survey_response');
                      questionAnswer.addQuery('instance', taskAssessment.getValue('instance'));
                      questionAnswer.addQuery('question', questionId);
                      questionAnswer.query();
                      if(questionAnswer.next()){
                          return questionAnswer.getValue('response');
                      }
                      else{
                          return '';
                      }
                  }
                  else{
                      return '';
                  }
              },
              
              type: 'CustomTaskAssessmentUtil'
          };
          

           

          2. Update your Assessment questions to call the script include in the default value (you might need to add the "Default value" field to the form)

             

               Default value: javascript: new CustomTaskAssessmentUtil().getExistingValue(RP.getParameterValue('sysparm_task_assessment'), 'sys_id_of_the_question')

            

               Replace sys_id_of_the_question with the sys_id of the question, you can get it by doing a right click on the form header and using Copy sys_id. Do this      for each of your questions

           

          This should do exactly what you want.

           

          Hope it helps you