GRC Advanced Risk : Sample script to read questionnaire and set values of factors in Inherent assmt

Nagasai Ram San
Tera Contributor

 

GRC Advanced Risk : Sample script to read questionnaire and set values of factors in Inherent assessment

i need sample script to read questionaries' in Risk identification record. The response has to be used to calculate automated script factor. Please share sample script for one field in questionarrie response to automated script factor score caluclation .

 

NagasaiRamSan_0-1678873867694.png

 

1 REPLY 1

Rajesh_Singh
Kilo Sage

@Nagasai Ram San 

 

you can create a script to read the responses from the questionnaire associated with a risk identification record and use these responses to calculate the factor scores for the inherent assessment. Here's a sample script that demonstrates how to read a specific questionnaire response and use it to calculate a factor score:

 

// Sample script to read questionnaire responses and calculate factor scores

// Function to get the score based on the response value
function getScore(responseValue) {
    // Define the scoring logic based on your requirements
    // For this example, we'll use a simple scoring logic
    if (responseValue === 'high') {
        return 5;
    } else if (responseValue === 'medium') {
        return 3;
    } else if (responseValue === 'low') {
        return 1;
    } else {
        return 0;
    }
}

// Retrieve the risk identification record
var riskId = 'RISK_ID'; // Replace 'RISK_ID' with the actual sys_id of the risk identification record
var riskGr = new GlideRecord('grc_risk');
riskGr.get(riskId);

// Retrieve the assessment questionnaire associated with the risk identification record
var assessmentGr = new GlideRecord('asmt_assessment_instance');
assessmentGr.addQuery('source_table', 'grc_risk');
assessmentGr.addQuery('source_id', riskId);
assessmentGr.query();

if (assessmentGr.next()) {
    // Retrieve the response for a specific question in the questionnaire
    var questionId = 'QUESTION_ID'; // Replace 'QUESTION_ID' with the actual sys_id of the question
    var responseGr = new GlideRecord('asmt_assessment_instance_question');
    responseGr.addQuery('assessment_instance', assessmentGr.sys_id);
    responseGr.addQuery('question', questionId);
    responseGr.query();

    if (responseGr.next()) {
        // Get the response value and calculate the factor score
        var responseValue = responseGr.value;
        var factorScore = getScore(responseValue);

        // Set the factor score in the risk identification record
        riskGr.u_factor_score = factorScore;
        riskGr.update();
    }
}

In this example, you need to replace 'RISK_ID' with the actual sys_id of the risk identification record and 'QUESTION_ID' with the actual sys_id of the question you want to read from the questionnaire. The getScore() function is a sample function to demonstrate how to calculate the factor score based on the response value. You should modify this function to match your organization's scoring logic.

This script reads the response to a specific question, calculates the factor score based on the response value, and sets the factor score in the risk identification record's u_factor_score field (assuming you have a custom field named u_factor_score). You can modify the script to read multiple questions and calculate multiple factor scores as needed.

If you found my response helpful or applicable, please consider marking it as correct or helpful to assist others who may be seeking the same information.

---------------
Regards,
Rajesh Singh