- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 10-10-2019 02:37 AM
ServiceNow do not provide in the change process the Risk Assessment calculation via ATF. Without risk calculation it not possible to proceed to the next step. Also, it is not possible to interact with the popup window of the questionnaire and to press it's submit button via the ATF available steps.
You can set the risk value by running the server side script but the whole assessment process will be ignored, also the risk calculation based on the type of answers in the questionnaire and their weight.
Below you can find only one ATF Server Side Script Step for Change Risk Assessment. You will need the change sys_id from the step before running this server script. Also, you will need to adjust the metric type and metric names and use your own. Enjoy.
(function(outputs, steps, stepResult, assertEqual) {
//get change reord
var changeID = steps('9ea11010db88cc505b6a7d78f496192a').record_id; //change record id created in step before
var justCreatedGR = new GlideRecord('change_request');
if (justCreatedGR.get(changeID)) {
//create assessment
var metricType = '2e3ab7f1d7033200532c24837e61034b'; //sys_id of the metric type you can find in change_risk_asmt table
var assessmentDetails = new SNC.AssessmentCreation().createAssessments(metricType, justCreatedGR.sys_id,justCreatedGR.requested_by, false, "").split(",");
var asmtInstanceSysId = assessmentDetails[0];
//set response in assessment questions
var setResponse = new GlideRecord('asmt_assessment_instance_question');
setResponse.addQuery('instance', asmtInstanceSysId);
setResponse.query();
while (setResponse.next()) {
if (setResponse.metric.name == 'Control Effectiveness') {
setResponse.value = 5;
} else if (setResponse.metric.name == 'occurrence probability') {
setResponse.value = 5;
} else if (setResponse.metric.name == 'impact') {
setResponse.value = 5;
}
setResponse.update();
}
//set assessment to complete and link to task id
var justUpdatedInst = new GlideRecord('asmt_assessment_instance');
if (justUpdatedInst.get(asmtInstanceSysId)) {
justUpdatedInst.state = "complete";
justUpdatedInst.task_id = changeID;
justUpdatedInst.update();
}
//calculate assessment result and update change record with calculated risk
var calculatedRisk = new ChangeRiskAsmt().calculateRisk(justCreatedGR);
if (calculatedRisk.riskUpdated) {
stepResult.setOutputMessage("calculatedRisk.risk "+calculatedRisk.risk);
justCreatedGR.risk = calculatedRisk.risk;
justCreatedGR.update();
}
return true; // pass the step
} else {
stepResult.setOutputMessage("Failed to calculate risk");
return false; // fail the step
}
})(outputs, steps, stepResult, assertEqual);
- 1,767 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
Are you creating the change record in a previous step? If so, is there a way to add the sys ID of the change record to this script dynamically in ATF?
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hey Sergo....Thanks for this article Man! The script is working fine in the background script but when i tried to run this as an ATF step...it is not creating the assessment record and showing a log saying like noquestions. Any idea on this?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Did you ever figure this out? I'm having a similar problem with noquestions but it is doing it in script background as well.