Survey Response to Ticket form

BK9
Tera Contributor

Hi All,

I'm looking for a possible way to possibly set up a reference and dot-walk to survey responses on the form of the associated ticket. For example, if I have an incident that triggers a survey, I would like those survey responses to be viewable within a tab on the incident form. I've done this with a relationship and related list but would like to display the question and answers in a tab on the form. Any help would be great. See a mock-up below:

find_real_file.png

5 REPLIES 5

I haven't tested this at all, but it should be a good starting place for the background script.

var gr = new GlideRecord('incident');
gr.addEncodedQuery('u_survey=NULL'); //Reference field you created pointing to asm_assessment_instance
gr.addQuery('active', false); //Only get old incident. Assuming older surveys would only be for Closed incidents at this point
gr.query();
if (gr.next()) {
    var gr2 = new GlideRecord('asmt_assessment_instance');
    gr2.addQuery('task_id', gr.sys_id); //Find survey related to incident
    gr2.addQuery('state', 'complete'); //only grab completed surveys
    gr2.addQuery('metric_type', 'SYS_ID of Specific Survey you are mapping'); //Only grab the Incident Survey you are interested in
    gr2.query();
    if (gr2.next()) {
        var gr3 = new GlideRecord('asmt_metric_result'); //Loop through all survey results from this specific survey instance
        gr3.addQuery('instance', gr2.sys_id);
        gr3.query();
        while (gr3.next()) {
            if (gr3.metric.name == 'L1 Ease of Contact') { //This is the name from the Survey Question. Can be found on Survey Designer
                gr.u_survey_answer1 = gr3.string_value; //Map the Survey Results field to the Custom field on the Incident Tabl
            }
            if (gr3.metric.name == 'XYZ') { //Copy and Paste If Block as many times as you have questions to map
                gr.u_survey_answer2 = gr3.string_value; //
            }
            if (gr3.metric.name == 'ABC') { //If we succesfully found the Question we wanted, map the field.
                gr.u_survey_answer3 = gr3.string_value; //
            }
        }
    }
    gr.autoSysFields(false); // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on
    gr.setWorkflow(false);
    gr.update();
}