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.

Assessment creation through change request UI is not working

ShreeyaSatam
Tera Contributor
Hi Team,
1.I have created Metric type with questionnaires on change request table
2. Created Ui Action which displays on change request form
3. Created Script includebAjax which can generate Assessments
4. Create Ui page which opens when users click on the UI action and displays the assessment questions to display
I have tried below APIs to generate assessments , however , assessment instance is not generating
new global.AssessmentUtils().createAssessments(assid, changeid, userud);
var result = new SNC.AssessmentCreation().createAssessments(assid, changeid, userud);
My script include is-
var ChangePCRAjax = Class.create();
ChangePCRAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    // Create the assessment instance (or reuse if one exists) and return its sys_id
    createOrGetInstance: function() {
       
        var str = ' ';
        var changeId = this.getParameter('sysparm_change_id');
        var assessmentId = 'a139ed1587513e10fd030fe80cbb359a';//Metric type post change review sysy id
        var userID =this.getParameter('sysparm_user_id');
       
        str += 'ChangePCRAJAX: starting creation for changeID ' +changeId + ' '+ userID +'\n';

        // var result = new global.AssessmentUtils().createAssessments(assessmentId, changeId, userID);
        var result = new SNC.AssessmentCreation().createAssessments(assessmentId, changeId, userID);
        result = result.split(',');
    str += ' '+ result +'\n';
        var instanceId = result[0];
        str += ' '+ instanceId + '\n';
        gs.info(str);
        var grInstance = new GlideRecord('asmt_assessment_instance');
        if (grInstance.get(instanceId))
            // grInstance.setValue('task_id', changeId);
            // grInstance.setValue('state', 'ready');
            // grInstance.insert();
       

        return JSON.stringify({
            instance: instanceId
        });



    },


    // Check completion
    isInstanceComplete: function() {
        var id = this.getParameter('sysparm_instance');
        var gr = new GlideRecord('asmt_assessment_instance');
        if (gr.get(id)) {
            var complete = (gr.state == 'complete'); // state is a choice; 'complete' is the value
            return JSON.stringify({
                complete: !!complete
            });
        }
        return JSON.stringify({
            complete: false
        });
    },

    type: 'ChangePCRAjax'
});
 
The requirement is when user click on the ui action then display a page of questionairres to submit when change state moves to close 
 
Can some one assist me to resolve this
0 REPLIES 0