Newer Version Available

This content describes an older version of this product. View Latest

Customize Synced Contact Record Fields Using CTRDataSyncFunction

Although the provided CTRDataSyncFunction Lambda automatically syncs many of the fields between Amazon’s contact record (previously called contact trace record or CTR) and a VoiceCall record, you can customize this function to sync additional fields.

The CTRDataSyncFunction Lambda documentation lists all the fields that are automatically synced with a VoiceCall record. Use these instructions to sync more fields.

  1. In your Salesforce org, create a custom field on the VoiceCall object for the desired attribute in the CTR data model.
  2. In Amazon Connect, select the CTRDataSyncFunction Lambda function. From the menu select Actions | Export function so that you can get access to the function source code. If you already have the source code for this function, you don’t need to perform this step.

    Export Lambda function

  3. In the utils.js file for the CTRDataSyncFunction Lambda, update the end of the transformCTR(ctr) function (where there’s a comment to Add custom fields here).
    1// Check if there are custom contact attributes
    2if (ctr.Attributes) {
    3    let callAttributes = {};
    4 
    5    // Get contact attributes data into call attributes
    6    callAttributes = getCallAttributes(ctr.Attributes);
    7
    8    // Add custom fields here ← ADD YOUR CODE HERE!!!
    9
    10    voiceCall.callAttributes = JSON.stringify(callAttributes);
    11}
    12...

    In that location, you can add any custom attributes to the callAttributes object. Add this code before the JSON.stringify(callAttributes) line. Your custom attributes are synced along with the automatically-synced attributes. The following example adds two fields to the list of synced fields:

    1// Check if there are custom contact attributes
    2if (ctr.Attributes) {
    3    let callAttributes = {};
    4 
    5    // Get contact attributes data into call attributes
    6    callAttributes = getCallAttributes(ctr.Attributes);
    7
    8    // Add custom fields here
    9
    10    // Custom field from ctr.Attributes 
    11    if (ctr.Attributes.ConnectionAttempts) {
    12        callAttributes.ConnectionAttempts__c = ctr.Attributes.ConnectionAttempts;
    13    }
    14    // Custom field in ctr (but not in ctr.Attributes)
    15    if (ctr.DisconnectReason) {
    16        callAttributes.DisconnectReason__c = ctr.DisconnectReason;
    17    }
    18 
    19    voiceCall.callAttributes = JSON.stringify(callAttributes);
    20}
    21...
  4. Deploy the new version of the Lambda function in your Amazon Connect instance.

    To learn more about managing Lambda function versions, see Lambda function versions in the AWS Lambda Developer Guide.

In subsequent calls, the new data is synced.