logo

NJP

ATF Server Side Script Step for Change Risk Assessment [HOWTO]

Import · Oct 10, 2019 · article

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);
View original source

https://www.servicenow.com/community/itsm-articles/atf-server-side-script-step-for-change-risk-assessment-howto/ta-p/2308403