Update Normal Change Request workflow to set all Non PROD/DR changes to LOW risk

Carol2
Tera Contributor

Hi, 

 

A user has an ask to set all NonProd and DR change request - "normal" risk to a low regardless of the risk assessment that is completed. Here is the code changes but for some reason the workflow script doesn't work.

 

if (workflow.scratchpad.ProdDR == false) {
workflow.info("NewRiskCheck IfRisk NonPROD ONLY Fired");
current.setValue('risk', 4);
} else if (riskvalue < current.risk) {
workflow.info("NewRiskCheck IfRisk PROD/DR Fired");
current.setValue('risk', riskvalue);
}

 

please help.

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Carol2 

 

How you are identifying a change for NON-prod and DR? If you have any field, you can set them in Risk condition and set the risk Low. That will be more easy and straight forward way. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

the code i am asked to modify: 

var h;
var m;
var l;
var assessmentinstancesysid = '';
var assessmentvalue = 0;
var critservices = false;
var calculateriskvalue = 0;
var riskvalue = 4;
var T1_T2_Riskvaluea = gs.getProperty('change.impactedservices.riskcalc.T1_T2');
var T1_T2_Riskvalue = parseInt(T1_T2_Riskvaluea);


var getAssessInst = new GlideRecord('asmt_assessment_instance');
getAssessInst.addQuery('state', 'complete');
getAssessInst.addQuery('task_id', current.sys_id);
getAssessInst.setLimit(1);
getAssessInst.orderByDesc('sys_created_on');
getAssessInst.query();

workflow.info("NewRiskCheck getAssessInst rowcount" + getAssessInst.getRowCount());

while (getAssessInst.next()) {
    workflow.info("NewRiskCheck getAssessInst numbert" + getAssessInst.number);
    assessmentinstancesysid = getAssessInst.sys_id;
    var getThresholds = new GlideRecord('change_risk_asmt_threshold');
    getThresholds.addQuery('assessment', getAssessInst.metric_type);
    getThresholds.query();
    workflow.info("NewRiskCheck getThresholds rowcount" + getThresholds.getRowCount());
    while (getThresholds.next()) {
        if (getThresholds.risk == 2) {
            h = getThresholds.score_greater_than.toString();
        } else if (getThresholds.risk == 3) {
            m = getThresholds.score_greater_than.toString();
        } else if (getThresholds.risk == 4) {
            l = getThresholds.score_greater_than.toString();
        }
    }

    var getAssessresults = new GlideRecord('asmt_category_result');
    getAssessresults.addQuery('assessment_group', getAssessInst.assessment_group);
    getAssessresults.addQuery('source_id', current.sys_id);
    getAssessresults.query();
    workflow.info("NewRiskCheck getAssessresults rowcount" + getAssessresults.getRowCount());
    while (getAssessresults.next()) {
        assessmentvalue = parseInt(getAssessresults.rating);
    }

    var checkimpactedservices = new GlideRecord('task_cmdb_ci_service');
    checkimpactedservices.addEncodedQuery('cmdb_ci_service.ref_cmdb_ci_service.busines_criticalityIN1 - most critical,2 - somewhat critical^task=' + current.sys_id);
    checkimpactedservices.query();
    workflow.info("NewRiskCheck checkimpactedservices rowcount" + checkimpactedservices.getRowCount());
    if (checkimpactedservices.hasNext()) {

        critservices = true;
    }

}

calculateriskvalue = assessmentvalue + T1_T2_Riskvalue;

if (critservices && (calculateriskvalue >= parseInt(h))) {
    riskvalue = 2;
} else if (critservices && (calculateriskvalue >= parseInt(m))) {
    riskvalue = 3;
} else if (critservices && (calculateriskvalue >= parseInt(l))) {
    riskvalue = 4;
}
 
if (workflow.scratchpad.ProdDR == false) {
workflow.info("NewRiskCheck IfRisk NonPROD ONLY Fired");
current.setValue('risk', 4);
} else if (riskvalue < current.risk) {
workflow.info("NewRiskCheck IfRisk PROD/DR Fired");
current.setValue('risk', riskvalue);
}

Sorry mate, I am not a developer. @Sandeep Rajput any help here.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************