2

Background

My question is similar to Eliot's, though I am asking about Event Context.

"inArguments": [
    { "FirstName":"{{Event.__EventDefinitionKey__.FirstName}}" }
]

Unlike Activities events cannot be placed anywhere in the journey so I assume EventDefinitionKey must always be the same for a particular journey.

Question

Is it possible to retrieve an Event Key (EventDefinitionKey) using Data Bindings? So that I don't bother updating the config.json file with the event key each time.

2 Answers 2

4

I don't know of any possibility to retrieve the event definition key using data binding, but here is the solution I use for my custom activities:

  • I added a field to the configuration dialog of the custom activity where I enter the event definition key when configuring the activity
  • When the configuration is finished I construct/overwrite the arguments with the now correct data binding expressions in customActivity.js

Using this solution you don't need to adapt the config.json and host a custom activity for every journey and only add an additional input field to your configuration wizard.

Additional field in configuration wizard interface:

<input id="eventDefinitionKey" placeholder="journey entry event's event definition key" type="text" required="required" minlength="1">

Setting the inArguments on save in customActivity.js:

var eventDefinitionKey = $('#eventDefinitionKey').val();
payload['arguments'].execute.inArguments = [{
    'FirstName': '{{Event.' + eventDefinitionKey + '.FirstName}}'
}];

An example can be found on my github account:

1
  • This is a good approach, but in this case the user must put the correct event key each time they set up a new journey.
    – Eduard
    Commented Jul 26, 2017 at 7:45
3

Another option apparently is using requestedInteraction together with a requestInteraction event called by the Custom Activity.

Here is an example code:

connection.on('requestedInteractionDefaults', function(settings) { 
    if( settings.error ) {
         console.error( settings.error );
    } else {
         defaults = settings;
    }
    console.log('defaults', defaults);
    var eventKey = retrieveKey(defaults.email[0]);
    console.log('EventKey', eventKey);
});


// Assume that the string of the format  
// '{{Event.ContactEvent-72af1529-1d7d-821e-2a08-34fb5068561d."EmailAddress"}}' 
// It will return 'ContactEvent-72af1529-1d7d-821e-2a08-34fb5068561d' 
function retrieveKey (string) {
    var pos1 = string.indexOf(".");
    var pos2 = string.indexOf(".", (pos1 + 1) );
    var result = string.substring( (pos1 + 1) , pos2);
    return result;
}

And console output:

enter image description here

1
  • 3
    Inspired by the answer. By triggering "requestInteraction" and upon receiving "requestedInteraction", you can access eventDefinitionKey from settings.triggers[0].metaData.eventDefinitionKey
    – frogcoder
    Commented Dec 11, 2017 at 11:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .