Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

ATF Risk assessment step

Ashley45
Tera Contributor

i'm trying to fill out the risk assessment from a normal change. Once i click risk assessment it opens the form and the i tried using a 'set components values' step to set the response for each question but i get an error that it was unable to set the component and component not found

 

Error:

Ashley45_0-1721740780111.png

 

 

Test Step(s):

Ashley45_1-1721740856779.png

Ashley45_3-1721741075093.png

 

Assessment form:

Ashley45_2-1721741047627.png

 

 

1 ACCEPTED SOLUTION

Brian Lancaster
Kilo Patron

You have to do this with a custom Server Side Test step.

https://www.servicenow.com/community/developer-articles/how-to-atf-server-side-script-step-for-chang...

This example is using the out of the box question so you will need to modify it slightly. 

View solution in original post

4 REPLIES 4

Brian Lancaster
Kilo Patron

You have to do this with a custom Server Side Test step.

https://www.servicenow.com/community/developer-articles/how-to-atf-server-side-script-step-for-chang...

This example is using the out of the box question so you will need to modify it slightly. 

Is this a limitation? I can get to the form see all the questions and answers, find the component values but it has a problem selecting them when the test in ran?

Yes this is a limitation on in AFT. The work around is to create your own Server side test step.

Hi Brian,

 

I attempted to use the ATF Server-Side Script Step for Change Risk Assessment, but it failed due to an error message stating "Failed to calculate risk". I am unclear about the cause of this issue. Additionally, I did not find the metric type sys_ids in the change_risk_asmt table.

Furthermore, although I successfully populated some fields using Set Component Values (Custom UI), I am unable to populate the following three fields.

Does this affect the Externally Facing Systems?
Is there a redundancy plan in place?
Will this change require a Planned Outage?

 

Here is my script:

 

Description generation script:

function generateDescription() {//Note that you will need to update all imputs to the name of your imputs if they are different then the mones listed below.
    // the global variable 'step' represents the current glide record
    var description = "Set Risk Assessment for " + step.inputs.u_record.getDisplayValue() + "\n";
    // your code here
    description += "With the following Values: \n\n";
    description += "Does the change affect a critical CI or Business service?: " + step.inputs.u_ci_business_service.getDisplayValue() + "\n";
    description += "Does this affect the Externally Facing Systems?: " + step.inputs.u_grid_system.getDisplayValue() + "\n";
    description += "How Complex is the Change (where complexity is a function of number of impacted Cis, number of tasks involved, number of teams involved)?: " + step.inputs.u_complexity_of_change.getDisplayValue() + "\n";
    description += "How difficult is the change to back out or revert?: " + step.inputs.u_difficult_to_revert.getDisplayValue() + "\n";
    description += "Is there a redundancy plan in place?: " + step.inputs.u_redundancy_plan.getDisplayValue() + "\n";
    description += "How difficult is it to verify the change was successful?: " + step.inputs.u_verification_change.getDisplayValue() + "\n";
    description += "Will this change require a Planned Outage?: " + step.inputs.u_planned_outage.getDisplayValue() + "\n";
   
    return description;
}
 generateDescription();
 
Step execution script:
(function executeStep(inputs, outputs, stepResult, timeout) {
    //set variables for all change inputs
    var changeID = inputs.u_record.toString();
    var bis_svc = inputs.u_ci_business_service;
    var complex = inputs.u_complexity_of_change;
    var dificult = inputs.u_difficult_to_revert;
    var redundancy = inputs.u_redundancy_plan;
    var verify = inputs.u_verification_change;
    var grid = inputs.u_externally_system;
    var planned = inputs.u_u_planned_outage;

    var justCreatedGR = new GlideRecord('change_request');
    if (justCreatedGR.get(changeID)) {//get change record to pull fields o who will take they survey.
        //create assessment
        var metricType = '8c3a2c44d7211100158ba6859e6103fe'; //sys_id of the metric type you can find in change_risk_asmt table
        var assessmentDetails = new global.ChangeRiskAsmtSNC()._createAsmt(metricType, justCreatedGR.sys_id, justCreatedGR.assigned_to);
        var asmtInstanceSysId = assessmentDetails; //survey sys_id

        //set response in assessment questions
        var setResponse = new GlideRecord('asmt_assessment_instance_question');
        setResponse.addQuery('instance', asmtInstanceSysId);
        setResponse.query();

        while (setResponse.next()) { //set assessment answers
            if (setResponse.metric.name == 'How Complex is the Change (where complexity is a function of number of impacted Cis, number of tasks involved, number of teams involved)?') {
                setResponse.value = complex;
            } else if (setResponse.metric.name == 'How difficult is the change to back out or revert?') {
                setResponse.value = easy;
            } else if (setResponse.metric.name == 'How difficult is it to verify the change was successful?') {
                setResponse.value = easy;
            } else if (setResponse.metric.name == 'Does this affect the Externally Facing Systems?') {
                setResponse.value = yes;
            } else if (setResponse.metric.name == 'Will this change require a Planned Outage?') {
                setResponse.value = no;
            } else if (setResponse.metric.name == 'Is there a redundancy plan in place?') {
                setResponse.value = yes;
            } else if (setResponse.metric.name == 'Does the change affect a critical CI or Business service?') {
                setResponse.value = bis_svc;
            } else {
                setResponse.value = critical;
            }
            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 global.RiskCalculator(justCreatedGR).evaluateRiskImpact();
        if (calculatedRisk.riskEvaluation.risk.value == 4 || calculatedRisk.riskEvaluation.risk.value == 3 ||
            calculatedRisk.riskEvaluation.risk.value == 2) {//Check is asessment returned one of the expected values
            stepResult.setOutputMessage("calculatedRisk.risk " + calculatedRisk.riskEvaluation.risk.value);
            justCreatedGR.risk = calculatedRisk.riskEvaluation.risk.value;
            justCreatedGR.update();
        }
        stepResult.setSuccess();//successful test
        return;
    } else {
        stepResult.setOutputMessage("Failed to calculate risk");
        stepResult.setFailed(); // fail the step
    }
}(inputs, outputs, stepResult, timeout));