display the dependent question on the smart assessment form based on the other table data

harinya
Tera Contributor

On the smart Assessment form , for one of question user selects the 'next' or 'move' it should check the other table data for that entity has value or not if yes it should show the dependent question if not dependent ques not required
can someone please help on that
Thanks in Advance

3 REPLIES 3

Shivalika
Mega Sage

Hello @harinya 

 

Use below on change catalog client script and Script include. (NOTE TO REPLACE with correct fields) 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    // Call the Script Include to check the other table data
    var ga = new GlideAjax('CheckEntityData');
    ga.addParam('sysparm_name', 'checkData');
    ga.addParam('sysparm_entity', g_form.getValue('entity_field')); // Replace 'entity_field' with the actual field name
    ga.getXMLAnswer(function(response) {
        var result = response.responseXML.documentElement.getAttribute('answer');
        if (result === 'true') {
            // Show the dependent question
            g_form.setDisplay('dependent_question', true); // Replace 'dependent_question' with the actual field name
        } else {
            // Hide the dependent question
            g_form.setDisplay('dependent_question', false); // Replace 'dependent_question' with the actual field name
        }
    });
}

Script Include

This script include will check if the other table data for the entity has a value or not.

var CheckEntityData = Class.create();
CheckEntityData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    checkData: function() {
        var entity = this.getParameter('sysparm_entity');
        var gr = new GlideRecord('other_table'); // Replace 'other_table' with the actual table name
        gr.addQuery('entity_field', entity); // Replace 'entity_field' with the actual field name
        gr.query();
        if (gr.next()) {
            return 'true';
        } else {
            return 'false';
        }
    }
});



Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Connor Levien
ServiceNow Employee
ServiceNow Employee

Instead of modifying the progression script. I would suggest to copy the values from the entity to answer the questions so they are not required, you can write a flow to pre-populate answers to questions in Smart assessments so they are not required. Additionally, this can help from an audit perspective to make it clear what the values were when the assessment was done

Shivalika
Mega Sage

Hello @harinya 

 

Please confirm if you checked my answer. Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for my efforts and also it can move from unsolved bucket to solved bucket. 

 

Regards, 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeE