We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Localization of Smart Assessment

GeraldKirby
Kilo Sage

Hi,

 

Any guides/articles on how to translate smart assessments?

 

@Alex Coope - SN 

16 REPLIES 16

Alex Coope - SN
ServiceNow Employee

Hi @GeraldKirby,

Soon ( tm ) 🙂

There's some changes that need to happen behind the scenes before I can provide another LF artifact. Just know, I am working with the product team on this one,

Many thanks,
Kind regards

--------------------------------------------------------------------
Director of Globalization Deployment, Internationalization

Thanks @Alex Coope - SN . Appreciate your quick response 😊

Hi @GeraldKirby,

I'm not going to release this in my usual way (because things are going to change pretty significantly in a future release of Smart Assessments), however for the right now, you can use this:

Create the UI action on the [sn_smart_asmt_template] table, calling the internal name of "proto_grc_assessment_templates" (use this for the LF config record, calling it "Proto - GRC Assessment Templates", then create a processor script called "LF_grcAssessementTemplates" with the following query:

var LF_grcAssessmentTemplates = Class.create();
LF_grcAssessmentTemplates.prototype = Object.extendsObject(global.LFArtifactProcessorSNC, {
    category: 'localization_framework', // DO NOT REMOVE THIS LINE!

    /**********
     * Extracts the translatable content for the artifact record
     * 
     * @param params.tableName The table name of the artifact record
     * @param params.sysId The sys_id of the artifact record 
     * @param params.language Language into which the artifact has to be translated (Target language)
     * @return LFDocumentContent object
     **********/
    getTranslatableContent: function(params) {
        /**********
         * Use LFDocumentContentBuilder to build the LFDocumentContent object
         * Use the build() to return the LFDocumentContent object
         **********/

        var tableName = params.tableName;
        var sysId = params.sysId;
        var language = params.language;
        var lfDocumentContentBuilder = new global.LFDocumentContentBuilder("v1", language, sysId, tableName);

        // let's get the assessment template
        var getAsTemp = new GlideRecord("sn_smart_asmt_template");
        getAsTemp.addQuery('sys_id', sysId);
        getAsTemp.query();
        if (getAsTemp.next()) {
            // now we have our template, we need to loop through each level

            // let's process the translatable fields on this record
            lfDocumentContentBuilder.processTranslatableFieldsForSingleRecord(getAsTemp, "Assessment Template", "Name");

            // let's get the template sections
            var getAsTempSec = new GlideRecord("sn_smart_asmt_section");
            getAsTempSec.addQuery('assessment_template', getAsTemp.sys_id.toString());
            getAsTempSec.orderBy("order");
            getAsTempSec.query();
            while (getAsTempSec.next()) {
                // let's process the translatable fields on this record
                lfDocumentContentBuilder.processTranslatableFieldsForSingleRecord(getAsTempSec, "Assessment Section", "Name");

                // now we need to get the questions in the section
                var getAsQues = new GlideRecord('sn_smart_asmt_question');
                getAsQues.addQuery('assessment_template', getAsTemp.sys_id.toString());
                getAsQues.orderBy('order');
                getAsQues.query();
                while (getAsQues.next()) {
                    // now we need to process the translatable fields on these records
                    lfDocumentContentBuilder.processTranslatableFieldsForSingleRecord(getAsQues, "Assessment Questions - " + getAsQues.label, "Question");

                    // now we need to get the options for the questions
                    var getAsQuesOpt = new GlideRecord('sn_smart_asmt_response_option');
                    getAsQuesOpt.addQuery('question', getAsQues.sys_id.toString());
					getAsQuesOpt.orderBy('order');
                    getAsQuesOpt.query();
                    while (getAsQuesOpt.next()) {
                        // lets process the translatable fields on these records
                        lfDocumentContentBuilder.processTranslatableFieldsForSingleRecord(getAsQuesOpt, "Assessment Questions - " + getAsQues.label, "Option");
                    }

                    // we need to process the question type as well
                    var getQuesType = new GlideRecord('sn_smart_asmt_question_type');
                    getQuesType.addQuery('sys_id', getAsQues.question_type.sys_id);
					getQuesType.orderBy('order');
                    getQuesType.query();
                    if (getQuesType.next()) {
                        // let's process the translatable fields
                        lfDocumentContentBuilder.processTranslatableFieldsForSingleRecord(getQuesType, "Assessment Question Type", "Name");
                    }
                }

            }
            // lets get the Template Conditions
            var getAssessmentCond = new GlideRecord('sn_smart_asmt_condition');
            getAssessmentCond.addQuery('assessment_template', getAsTemp.sys_id.toString());
			getAssessmentCond.orderBy('order');
            getAssessmentCond.query();
            while (getAssessmentCond.next()) {
                // let's process the translatable fields
                lfDocumentContentBuilder.processTranslatableFieldsForSingleRecord(getAssessmentCond, "Assessment Conditions", "Name");
            }
        }
        return lfDocumentContentBuilder.build();
    },

    /**********
     * Uncomment the saveTranslatedContent function to override the default behavior of saving translations
     * 
     * @param documentContent LFDocumentContent object
     * @return
     **********/
    /**********
        saveTranslatedContent: function(documentContent) {},
    **********/

    type: 'LF_grcAssessmentTemplates'
});

 
It should work, but like I said things are going to change pretty significantly in a future release making this obsolete,


Many thanks,
Kind regards

--------------------------------------------------------------------
Director of Globalization Deployment, Internationalization