How to show assessment responses on portal page?

akshay parekar1
Tera Contributor

Hi,

i have created ui action on company table and for a company record, there are assessments stored in related list.

If we open as assessment record, within its related list there is assessment instance of which we can see user responses (by clicking View responses button).

  Now, when i click ui action created on company table, for particular record i want to show the responses of last completed assessment on a form.

I was not clear how i can achieve that, can anyone please help?

1 ACCEPTED SOLUTION

Mallidi Suma
Tera Guru

Hi @akshay parekar1 ,

 

I created a UI action on the incident and click that will give the latest assessment UI page Survey Result.

 

Please find the below steps:-

1. Created a Client UI action called "View Survey Response" on Incident Table and added the below code in the Script Section.

 

Code:-

function showResponse() {
    var ga = new GlideAjax('CopyRITMWithVariables');
    ga.addParam('sysparm_name', 'getRecentIncAssessmentInstance');
    ga.addParam('sysparm_incID', g_form.getUniqueValue()); // If you are creating this UI action on the company table then it will fetch send that Company record sys_id to the server and it fetch the latest assessment Instances that are submitted.
    ga.getXML(ResponseFunction);
 
    function ResponseFunction(response) {
 
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var result = JSON.parse(answer);
 
        var id = result.SysID;
        var type = result.typeID;
 
        var url = 'assessment_take2.do?sysparm_assessable_sysid=' + id + '&sysparm_assessable_type=' + type + '&sysparm_reader_view=true';
 
//g_form.addInfoMessage("Id" + url);
 
        var d = new GlideOverlay({
            title: "User's Response",
            iframe: url,
            width: '80%',
            height: '100%',
            onAfterLoad: function() {
                var iframe = d.getIFrameElement();
                setTimeout(function() {
                    iframe.height = parseInt(iframe.height) + 1;
                }, 0);
            }
        });
        d.render();
    }
}

UI action Screenshot:-

 

Screenshot 2023-05-20 at 3.13.48 AM.png

 

Step 2:-

Created a client callable Script Include

Code:-

var CopyRITMWithVariables = Class.create();
CopyRITMWithVariables.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getRecentIncAssessmentInstance: function()
{
//sysparm_incID
var TypeID = {};
var inc_id = this.getParameter('sysparm_incID');
var asst_inst_rec = new GlideRecord('asmt_assessment_instance');
asst_inst_rec.addQuery('task_id',inc_id);
asst_inst_rec.orderByDesc('taken_on');
asst_inst_rec.query();
if(asst_inst_rec.next())
{
TypeID.SysID = asst_inst_rec.sys_id.toString();
TypeID.typeID = asst_inst_rec.metric_type.toString();
}
return JSON.stringify(TypeID);
},type: 'CopyRITMWithVariables'
});

 

Screenshot:-

Screenshot 2023-05-20 at 3.17.06 AM.png

 

Result:- 

Screenshot 2023-05-20 at 3.17.40 AM.png

 

Please mark my answer as helpful and accept it as a solution, if it helps!!

 

Thanks & Regards,

Suma.

View solution in original post

2 REPLIES 2

Mallidi Suma
Tera Guru

Hi @akshay parekar1 ,

 

I created a UI action on the incident and click that will give the latest assessment UI page Survey Result.

 

Please find the below steps:-

1. Created a Client UI action called "View Survey Response" on Incident Table and added the below code in the Script Section.

 

Code:-

function showResponse() {
    var ga = new GlideAjax('CopyRITMWithVariables');
    ga.addParam('sysparm_name', 'getRecentIncAssessmentInstance');
    ga.addParam('sysparm_incID', g_form.getUniqueValue()); // If you are creating this UI action on the company table then it will fetch send that Company record sys_id to the server and it fetch the latest assessment Instances that are submitted.
    ga.getXML(ResponseFunction);
 
    function ResponseFunction(response) {
 
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var result = JSON.parse(answer);
 
        var id = result.SysID;
        var type = result.typeID;
 
        var url = 'assessment_take2.do?sysparm_assessable_sysid=' + id + '&sysparm_assessable_type=' + type + '&sysparm_reader_view=true';
 
//g_form.addInfoMessage("Id" + url);
 
        var d = new GlideOverlay({
            title: "User's Response",
            iframe: url,
            width: '80%',
            height: '100%',
            onAfterLoad: function() {
                var iframe = d.getIFrameElement();
                setTimeout(function() {
                    iframe.height = parseInt(iframe.height) + 1;
                }, 0);
            }
        });
        d.render();
    }
}

UI action Screenshot:-

 

Screenshot 2023-05-20 at 3.13.48 AM.png

 

Step 2:-

Created a client callable Script Include

Code:-

var CopyRITMWithVariables = Class.create();
CopyRITMWithVariables.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getRecentIncAssessmentInstance: function()
{
//sysparm_incID
var TypeID = {};
var inc_id = this.getParameter('sysparm_incID');
var asst_inst_rec = new GlideRecord('asmt_assessment_instance');
asst_inst_rec.addQuery('task_id',inc_id);
asst_inst_rec.orderByDesc('taken_on');
asst_inst_rec.query();
if(asst_inst_rec.next())
{
TypeID.SysID = asst_inst_rec.sys_id.toString();
TypeID.typeID = asst_inst_rec.metric_type.toString();
}
return JSON.stringify(TypeID);
},type: 'CopyRITMWithVariables'
});

 

Screenshot:-

Screenshot 2023-05-20 at 3.17.06 AM.png

 

Result:- 

Screenshot 2023-05-20 at 3.17.40 AM.png

 

Please mark my answer as helpful and accept it as a solution, if it helps!!

 

Thanks & Regards,

Suma.

Thanks @Mallidi Suma  for replying!!