Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get the assessable record details in the assessement template question

prasanna16
Tera Contributor

Hi,

 

I am trying to automated default response for the assessment question trying the below script but it is not working

try {
/***Start of Custom Code. Please write your custom logic below. */

// Initialize result.value as null
result.value = null;

// Log the start of the script
gs.log('Starting default answer script for question instance: ' + questionInstanceId, 'AssessmentScript');

// Query the assessment instance question
var questionInstance = new GlideRecord('asmt_assessment_instance_question');
if (questionInstance.get(questionInstanceId)) {
// Log the question instance found
gs.log('Found question instance: ' + questionInstanceId, 'AssessmentScript');

// Get the assessment instance
var assessmentInstance = new GlideRecord('asmt_assessment_instance');
if (assessmentInstance.get(questionInstance.instance)) {
// Log the assessment instance found
gs.log('Found assessment instance: ' + assessmentInstance.sys_id, 'AssessmentScript');

// Get the assessable record (e.g., GRC Entity Type)
var assessableRecord = new GlideRecord('sn_ai_governance_asset_governance_details'); // Replace with your table
if (assessableRecord.get(assessmentInstance.document_id)) {
// Get the name field and set as default answer
result.value = assessableRecord.getValue('name');
// Log the retrieved value
gs.log('Default answer set to: ' + result.value, 'AssessmentScript');
} else {
// Log error if assessable record is not found
gs.log('Assessable record not found for document_id: ' + assessmentInstance.document_id, 'AssessmentScript');
result.value = 'Unable to retrieve data'; // Default response on error
}
} else {
// Log error if assessment instance is not found
gs.log('Assessment instance not found for sys_id: ' + questionInstance.instance, 'AssessmentScript');
result.value = 'Unable to retrieve data'; // Default response on error
}
} else {
// Log error if question instance is not found
gs.log('Question instance not found for sys_id: ' + questionInstanceId, 'AssessmentScript');
result.value = 'Unable to retrieve data'; // Default response on error
}

/***End of Custom Code. Do not modify anything below. */
} catch (ex) {
// Log the error
gs.log('Error in default answer script: ' + ex.message, 'AssessmentScript');
result.errorStatus = true;
result.errMessage = ex.message;
result.value = 'Unable to retrieve data'; // Default response on error
}

0 REPLIES 0