How do I add a field that will auto populate the inherent risk rating result in risk response task?

ChuanYanF
Tera Guru

Dear experts,

 

I would like to add a field which is the inherent risk rating result after the users have completed the risk assessment and the score will be reflected when they create a risk response task in the risk response form. I tried to create a new business rule which is as below. But it does not work, any suggestions to approach this matter?

 

(function executeRule(current, previous /*null when async*/) {
    if (!current.risk_assessment) {
        return;
    }

    var riskAssessment = new GlideRecord('sn_risk_advanced_risk_assessment_instance');
    if (riskAssessment.get(current.risk_assessment)) {
        current.inherent_risk_rating = riskAssessment.summary_inherent_risk_score;
    }
})(current, previous);
1 ACCEPTED SOLUTION

Hi, so I tried and this is the script that is working for now

(function executeRule(current, previous /*null when async*/) {

    if (!current.risk) {
        gs.info("dont have assosciated risk ")
        return; // Skip if there's no linked Risk or if Inherent Risk is already set
    }

    var risk = new GlideRecord('sn_risk_risk');
    if (risk.get(current.risk)) {  
        gs.info(current.risk);
        var assessment = new GlideRecord('sn_risk_advanced_risk_assessment_instance');
        assessment.addQuery('risk', risk.sys_id);
        assessment.orderByDesc('sys_created_on'); // Get the latest assessment
        assessment.query();

        if (assessment.next() && assessment.summary_inherent_risk_score) {  
            current.u_inherent_risk_rating = assessment.summary_inherent_risk_score;
            gs.info('Inherent Risk Score set to ' + assessment.summary_inherent_risk_score + ' for Risk Response Task: ' + current.sys_id);
        }
    }
})(current, previous);

View solution in original post

26 REPLIES 26

OK, let me go through from the start, so from risk record, we can click view assessment and it will bring us to the risk assessment. And then through the risk assessment, when create a risk response task a response task is generated based on your response.

ChuanYanF_0-1742543921060.png

ChuanYanF_1-1742543970473.png

 

 

Hello @ChuanYanF 

 

Now I have the whole picture. 

 

so, the "Assessment summary" in Risk Assessment has the "Inherent risk score". So you don't actually need to dot walk like that. 

 

Simply use this - Risk Response task -> risk assessment instance -> inherent score. 

 

Something like below 👇 

 

current.risk_assessment_instance.inherent score ( this field contains score) - //USE CORRECT NAMES

 

Copy this to current.inherent_score (This is the field to which you will copy above) 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

 

 

 

 

 

 

Regards,

 

 

 

 

 

 

 

Shivalika 

 

 

 

 

 

 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

 

 

 

 

 

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Isn't this the same as my script I provided above just now which is this?

(function executeRule(current, previous /*null when async*/) {
    // Access the inherent rating from the related risk record
    var inherentRating = current.risk.assessment_instance.summary_inherent_risk_score;

 

    // Set the desired field in the Risk Response task table to this value
    current.u_inherent_risk_rating = inherentRating;

Hello @ChuanYanF 

 

Yes, Now, I am able to relate all the things. 

Please add current.update(); at the end. 

 

Additionally add logs to check if it is fetching the values correctly. 

 

gs.log("FROM Assessment" + current.risk.assessment_instance.summary_inherent_risk_score); 

 

 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Regards,

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Shivalika 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Shivalika
Mega Sage

Hello @ChuanYanF 

 

Please confirm if you checked my answer. Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for my efforts and also it can move from unsolved bucket to solved bucket. 

 

Regards, 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeE