Using HappyCustomConfig to edit default language in Ticket-based IT Experience

By default language is set as English, if your ServiceNow platform language is different you need to change the default setting using the HappyCustomConfig

Create a HappyCustomConfig script include

The first thing you need to do is to create a new script include in the Global application scope with the following details:
Field
Value
Name
HappyCustomConfig
API name
global.HappyCustomConfig
Client callable
false
Application
Global
Accessible from
All application scopes
Active
true
Description
[optional]
 
The HappyCustomConfig script include is used for generating a configuration object that contains the data that will be passed to HappySignals. The HappyCustomConfig can be used to create data mapping for custom tables or be used for script-based data fetching for the default tables. The example script below can be used as a starting point for making your custom table mappings.
 
var HappyCustomConfig = Class.create();
HappyCustomConfig.prototype = {
    initialize: function () {
        var currentTimeMS = new GlideDateTime().getNumericValue();
        this.datestamp = new Date(currentTimeMS).toISOString();
    },

    /**
     * Configure function can override existing data mappings or  define mappings for tables not supported by the default configuration logic.
     * @param {GlideRecord} obj GlideRecord object that triggered response link creation
     * @param {JSON object} conf object that contains configurations made in HappyLinkCreator
     * @param {string} tableName name of the table where the GlideRecord object originated
     * @returns modified configuration object
     */
    Configure: function (obj, conf, tableName) {

        /* Available keys on base object described below
        Below keys correspond to specific fields on HappySignals cloud
        // MANDATORY DETAILS
        conf.esm = 'IT'; // top level categorization for the response eg. IT, HR, Security
        conf.ticket_type = ''; // type of ticket eg. Request, Incident etc.
        conf.category = ''; // survey form key, consult with HappySignals
        conf.ticket_number = ''; // ticket number or other identifier
        conf.opened_at = ''; // time when the ticket was opened
        conf.datestamp = ''; // time for the survey delivery, should be tied to datetime field on the ticket
        conf.language = ''; // language code eg. en, fr, es etc.

        // BENCHMARK DETAILS
        conf.contact_type = '';
        conf.country = '';

        // END USER DETAILS
        conf.employment_started_at = '';
        conf.endUserId = ''; // email address of the end-user

        // OTHER DETAILS
        conf.reassign = '';
        conf.assignment_group = '';
        conf.priority = '';
        conf.location = '';
        conf.company = '';
        conf.ci = '';
        conf.service = '';
        conf.secondary_category = '';
        conf.tertiary_category = '';
        conf.region = '';
        conf.vendor = '';
        conf.business_stc = '';
        conf.time_worked = '';
        conf.made_sla = '';
        conf.source_object = '';
        conf.source_id = '';
        */

        // short example of mapping interaction table fields
        switch (tableName) {
            case 'interaction':
                conf.esm = "IT";
                conf.ticket_type = "Interaction";
                conf.category = "other";
                conf.ticket_number = this.__getFieldValue(obj, 'number');
                conf.language = this.__getFieldValue(obj, 'opened_for.preferred_language');
                conf.datestamp = this.__getFieldValue(obj, 'closed_at', 'time');

                conf.contact_type = this.__getFieldValue(obj, 'type');
                conf.country = this.__getFieldValue(obj, 'opened_for.location.country');

                conf.assignment_group = this.__getFieldValue(obj, 'assignment_group');
                break;
        }

        return conf; // return the configuration object back to HappyLinkCreator to generate the response link
    },

    /**
     * Gets field values and returns them in a format expected by HappySignals
     * @param {glideRecordObject} record gliderecord of the object where the field value is retrieved
     * @param {string} field field name where the data is retrieved, supports dot-walking to reference fields
     * @param {string} returnType in what type the value is returned, options sys_id, value, time, displayValue
     * @returns return value from the given field
     */
    __getFieldValue: function (record, field, returnType) {

        returnType = returnType || 'displayValue'; // set default return type as displayValue if defining argument is not provided
        var returnValue = '', //set default return value
            elem = record.getElement(field); // get the possibly dot-walked element

        if (!gs.nil(elem) && !gs.nil(elem.toString())) {
            try {
                switch (returnType) {
                    case 'sys_id':
                        returnValue = elem.sys_id.toString();
                        break;
                    case 'value':
                        returnValue = elem.toString();
                        break;
                    case 'time':
                        var timeInMS = new GlideDateTime(elem.toString()).getNumericValue();
                        returnValue = new Date(timeInMS).toISOString(); // time fields need to be formatted to ISO8061 format
                        break;
                    default:
                        returnValue = elem.getDisplayValue();
                }
            } catch (e) {
                gs.info("HappyCustomConfig: mapping for field ({0}) unsuccessfull due to error: {1}", field, e.message);
                return ''; // failsafe to prevent other field processing from stopping
            }
            if (returnValue == undefined || returnValue == null) {
                returnValue = '';
            }
        }
        return returnValue;
    },

    type: 'HappyCustomConfig'
};

 

Update the HappyCustomConfig to reflect the Services used for example Incidents and Requests Items added to the Interaction configuration as described below

 

// short example of mapping interaction table fields

switch (tableName) {
    case 'incident': {
        // language fallback, apply to incidents
        if (gs.nil(this.__getFieldValue(obj, 'caller_id.preferred_language', 'value'))) {
          conf.language = 'fi'; // if language is not defined then set it to this
        }
        break;
  }
  case 'sc_req_item': {
      // language fallback, apply to request items
      if (gs.nil(this.__getFieldValue(obj, 'requested_for.preferred_language', 'value'))) {
          conf.language = 'fi'; // if language is not defined then set it to this
      }
      break;
  }
  case 'interaction': {
      conf.esm = "IT";
      conf.ticket_type = "Interaction";
      conf.category = "other";
      conf.ticket_number = this.__getFieldValue(obj, 'number');
      conf.language = this.__getFieldValue(obj, 'opened_for.preferred_language');
      conf.datestamp = this.__getFieldValue(obj, 'closed_at', 'time');
      conf.contact_type = this.__getFieldValue(obj, 'type');
      conf.country = this.__getFieldValue(obj, 'opened_for.location.country');
      conf.assignment_group = this.__getFieldValue(obj, 'assignment_group');
      break;
  }
}

 

After this change if user has the default platform language in ServiceNow they will be shown the finnish version of the Happiness factors in HappySignals platform.

Below is the link to supported language codes in survey forms.

What languages are available?