How to use Service Experience application with other than the supported default tables

By default, feedback related data can be mapped from incident and requested items tables. With some scripting it possible to map data beyond the predefined tables to HappySignals.

The overall process for collecting feedback for ServiceNow processes is two-fold:
1) sending the data to HappySignals and
2) getting the data back to ServiceNow with the HappySignals API
Sending the data to HappySignals is fairly simple, but requires a bit of scripting to get the correct data from your desired table. The second part process is a bit more complicated, it requires customisation of the HappySignals application in ServiceNow and the level of customisation required depends on the available fields on the table.

An important thing to note is that the table you want to map should extend the “Task” table in ServiceNow. Although, it is technically possible also to map tables that do not extend “Task”, this requires extensive customisation to the application. 

Sending data to HappySignals

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 () {

        this.dateStamp = new GlideDateTime().toString();

    },

    Configure: function (obj, conf, tableName) {

        try {

            this.obj = obj;
// Here you can do the mapping for your custom table

          // You should make sure that the values passed to HappySignals are in string format

            switch (tableName) {

                case 'sc_request': {

                    // Initialize conf object

                    conf.ticket_number = '';

                    conf.contact_type = '';

                    conf.reassign = '';

                    conf.business_stc = '';

                    conf.time_worked = '';

                    conf.assignment_group = '';

                    conf.priority = '';

                    conf.location = '';

                    conf.category = '';

                    conf.company = '';

                    conf.country = '';

                    conf.ci = '';

                    conf.service = '';

                    conf.secondary_category = '';

                    conf.tertiary_category = '';

                    conf.region = '';

                    conf.vendor = '';

                    conf.language = '';

                    conf.ticket_type = '';

                    conf.made_sla = '';

                    conf.datestamp = '';

                    conf.esm = "IT";

                 

                    conf.ticket_number = JSUtil.notNil(obj.number) ? obj.number + '' : '';

                    // Set current timestamp if empty

                    if (conf.datestamp == null || conf.datestamp == undefined) {

                        conf.datestamp = this.dateStamp;

                    }

                    break;

                }




            }

            return conf;

        } catch (e) {

            gs.warn('Error in HappyCustomConfig script include: ' + e.message);

        }

    },

    type: 'HappyCustomConfig()'

};

 

Create a notification for your custom table
Once you have created the HappyCustomConfig script include then you need to add the HappySignals voting buttons to the email notifications for your custom table. The notifications determine when and who will receive the HappySignals feedback survey. 
 
To add the HappySignals voting buttons to your notifications simply add the following mail script to them:
${mail_script:happysignals_vote}
Note that the feedback survey that is shown to the recipient after they click one of the voting buttons is the same as in the case of a general request.

Getting the feedback data back to HappySignals

The second part of the process is to get the feedback data related to your custom table back to ServiceNow. This consist of two parts, modifying the transform map so that fields in the HappySignals feedback table are filled correctly and displaying the data in HappySignals widgets.

Modify the Service Experience integration job

Modifying the integration only applies to application versions of 1.3.2 and lower.

If your custom table is related to a non-IT process such as HR or Finance and the ESM value that you pass to HappySignals is not “IT”, you will need to modify the HappySignals Integration Job to fetch the non-IT related feedbacks also. In the integration job you will need to modify the query parameters to include the ESM values you need, see the example below:
var esmValues = [

        'IT',

        'HR',

        'Finance'

    ];

var esmQuery = '';

var timestampQuery = '';



var rest = new sn_ws.RESTMessageV2();

rest.setEndpoint(endpoint + '/api/v2/responses');

rest.setHttpMethod('POST');

rest.setRequestHeader('Authorization', 'Bearer ' + gs.base64Encode(apikey));

rest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

rest.setRequestHeader('Accept', 'application/json');

for (var i = 0, j = esmValues.length; i < j; i++) {

    if (esmQuery === '') {

        esmQuery += encodeURIComponent('enterpriseClass__in') + '=' + encodeURIComponent(esmValues[i]);

    } else {

        esmQuery += '&' + encodeURIComponent('enterpriseClass__in') + '=' + encodeURIComponent(esmValues[i])

    }

}

if (timestamp > 0) {

    // Get only newer feedbacks than we already have

    timestampQuery = 'timestamp__gt=' + timestamp;

}

rest.setRequestBody(timestampQuery + '&' + esmQuery);

var response = rest.execute();

// now that we have the response
See our API documentation for more information about how to query the API.
 
Clone and modify the transform map “HappySignals Feedback Import”
The HappySignals API is used to fetch feedback data back to ServiceNow. In order to generate the feedback records and linked data to your ServiceNow instance a transform map is used. The application comes with a transform map that has defaults for incident and requested item processes, so you will need to add your own logic to the transform map to get your custom table to work.
 
We suggest that you make a duplicate of the existing transform map, modify the duplicate and then deactivate the original map. This way when we publish updates to the application the changes you have made to the transform map are not overwritten by the update. The transform map that you need to duplicate and modify is named “HappySignals Feedback Import”.

Showing the feedbacks on HappySignals widgets

Note that the following section only applies to ticket records that extend the “Task” table in ServiceNow. Currently, there is no way to customise the script that constructs the feedback widget contents and what fields it checks for widget content values. Below is a list of the field that the script checks on the ticket record to fill the values. Unfortunately, if your custom ticket record does not have the reference fields that the content script tries to use, the script execution will stop and the feedback won’t be visible on the agent widget. If you need to show the feedbacks on the agent widget and do not have the necessary fields on the custom record contact us at support@happysignals.com 
Value on the widget
Field on the ticket record
assigned_to
assigned_to
assigned_to_name
assigned_to.name
assigned_group
assignment_group
assigned_group_name
assignment_group.name
short_desc
short_description
ticket
number
ticket_id
sys_id
ticket_opened
sys_created_on
company
requested_for.company
caller
requested_for
caller_name
requested_for.name
country
requested_for.location.country
contact_type
contact_type
category
Defaults to “Request” with custom tables
ticket_duration
start_time = sys_created_on
end_time = closed_at
ticket_resolved
closed_at
catalogitem
cmdb_ci
resolved_by
resolved_by or closed_by
A valid field check is done against the ticket record table