The CreatorCon Call for Content is officially open! Get started here.

Writing a Risk Assessment Answer Back to Change Form Field

stvillil
Kilo Contributor

Hi, I am trying to take an answer of Risk Assessment and populate that info back to a field on the Change Form. I found a couple of articles on the wiki that include details on Incident survey results, but can seem to make it work for change and risk assessment.

Thanks in advance for any help you can provide.

1 ACCEPTED SOLUTION

You can modify the '//now iterate the answers' section. Get the sys_id of the question you want to capture the result for, just add a couple of lines after -



var key = arg.substring('QUESTION:'.length);


Assuming that you just want the value of the answer (which is the text of the answer, not the score), something like this might do it.



var key = arg.substring('QUESTION:'.length);
//below is the sys_id of the question you want the answer to
if(key == 'ae168e6b9d40b0c015cb6a9aa0e40572'){
var cr = new GlideRecord('change_request');
cr.get(taskID);
cr.work_notes = value; //update whatever field you want, value is the value of the answer
cr.update();

}


View solution in original post

12 REPLIES 12

Jay_Ford
Kilo Guru

While it's generally a bad idea to mess around with out of box script includes, we did in this case because there was a business need. We just have to keep a watch on it every time there's a new release. But here is what we did.

We added a few fields to the change_request table to track info about the risk assessments, including a field called 'Risk Score' (u_risk_score). Then modified the 'SurveyProcessor' script include.

We changed this:



if (taskAssessmentId) {
this.response.sendRedirect('task.do?sys_id=' + taskID);
}
else {
this.response.sendRedirect("survey_thanks.do?sysparm_survey=" + this.request.getParameter("sysparm_survey"));
}


To this:


if (taskAssessmentId) {
var uTask = new GlideRecord('change_request');
uTask.get(taskID);
uTask.work_notes = 'Risk assessment complete - Total risk value = ' + allscores;
uTask.u_risk_score = allscores;
uTask.u_risk_assessment_completed = gs.nowDateTime();
uTask.state = 0;
uTask.u_assessment_completed = true;
uTask.update();
this.response.sendRedirect('task.do?sys_id=' + taskID);
}
else {
this.response.sendRedirect("survey_thanks.do?sysparm_survey=" + this.request.getParameter("sysparm_survey"));
}


Sweety5
Tera Contributor

Hi @Jay.Ford , 

This is my requirement related to risk assessment .

https://community.servicenow.com/community?id=community_question&sys_id=2cb90ce8db714510ae8125091396...

Can you please help me with this requirement . 

Thanks in advance .

stvillil
Kilo Contributor

This is very helpful. I think I can handle it from here, but I may be asking how to reference particular questions on the RA. I have some time tomorrow to give it another shot with your script. If I get it, I'll mark it answered!


stvillil
Kilo Contributor

Hi Jay,

Any idea How I can reference particular questions on the Risk assessment and then populate the answer to a field on the change request form. Your script was very helpful, but I'm struggling retrieving and populating that info.