- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 01:48 AM - edited 01-05-2024 01:53 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 08:27 PM - edited 01-07-2024 08:32 PM
Typically, the Display value of the Metric (Question) is stored in the String Value field as per the Assessment Metric Definitions. But within the Assessment Instance Questions [asmt_assessment_instance_question] table currently used from your script, the String Value field is not fully populated.
You can try to pull data from the Metric Result [asmt_metric_result] table instead. This way, you can retrieve the answer along with the display value through the String Value field.
So your script could be like sample below.
(function executeRule(current, previous /*null when async*/ ) {
var assessmentResponses = [];
var assessmentQuestionGR = new GlideRecord('asmt_metric_result'); //replace the table
assessmentQuestionGR.addQuery('instance', current.sys_id);
assessmentQuestionGR.addNotNullQuery('actual_value'); //replace the field name
//assessmentQuestionGR.addQuery('valueISNOTEMPTY');
assessmentQuestionGR.query();
while (assessmentQuestionGR.next()) {
var question = assessmentQuestionGR.metric.getDisplayValue();
var answer = assessmentQuestionGR.string_value.toString(); //replace to string_value
assessmentResponses.push({
question: question,
answer: answer
});
}
// Update RITM Additional Comments with assessment responses
var ritm = new GlideRecord('sc_req_item');
if (ritm.get('sys_id', current.task_id)) {
var additionalComments = "\nAssessment Responses:\n";
for (var i = 0; i < assessmentResponses.length; i++) {
additionalComments += assessmentResponses[i].question + ': ' + assessmentResponses[i].answer + '\n';
}
ritm.comments += additionalComments;
ritm.update();
}
})(current, previous);
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 06:48 PM
thank you timi thats working fine and i have done similar changes only now its working fine .
now i have another qustion
there is screen short captured in the answers , i wnt that to populate it on same RITM additional comments as a link so that whenever we click the link i want show a preview of that snippet to be viewed how can we acheive this ,?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2024 08:27 PM
You can leverage the GlideSysAttachment API to retrieve the associated attachments of the question.
Then you can build a reference link to open the attachment viewer.
Sample below.
Based on the script I provided before, let add an exception in the while loop.
var assessmentResponses = [];
var assessmentQuestionGR = new GlideRecord('asmt_metric_result'); //replace the table
assessmentQuestionGR.addQuery('instance', current.sys_id);
assessmentQuestionGR.addNotNullQuery('actual_value'); //replace the field name
//assessmentQuestionGR.addQuery('valueISNOTEMPTY');
assessmentQuestionGR.query();
while (assessmentQuestionGR.next()) {
var question = assessmentQuestionGR.metric.getDisplayValue();
//If the question is in Attachment datatype
if (assessmentQuestionGR.metric.datatype.toString() === 'attachment') {
var attachments = [];
var attachment = new GlideSysAttachment();
var agr = attachment.getAttachments('asmt_metric_result', current.getUniqueValue()); //get all attachments
while (agr.next()) {
var attachmentID = agr.getUniqueValue();
var attachmentName = agr.getValue('file_name');
//build the url to open the document viewer
var uri = '[code]<a href="sys_attachment.do?view=true&sys_id=' + attachmentID + '">' + attachmentName + '</a>[/code]';
attachments.push(uri);
}
assessmentResponses.push({
question: question,
answer: attachments.join(',') //set answer
});
continue; //skip below lines and move to next question record in the loop
}
var answer = assessmentQuestionGR.string_value.toString(); //replace to string_value
assessmentResponses.push({
question: question,
answer: answer
});
}
Enjoy your result
Make sure you have enabled Document Viewer in the table.
Ref: Enable Document Viewer
Cheers,
Tai Vu