4

I'm developping a custom activity in NodeJS and I would like to know how can I get the name of the Data Extension I'm working with to put the name here :

payload['arguments'].execute.inArguments = [{
            'campaignNameKey': campaignNameKey,
            'csvName': csvName,
            "Prenom": "{{Contact.Attribute.DE_NAME.Prenom}}",
            "Nom": "{{Contact.Attribute.DE_NAME.Nom}}",
            "Mobile": "{{Contact.Attribute.Contacts.Mobile}}",
            "Campagne": "{{Contact.Attribute.Contacts.Campagne}}",
            "stopSMS": "{{Contact.Attribute.Contacts.stopSMS}}"
        }];

For the moment, I'm using the name of my test Data Extension ("Contacts") but I would like to be able to use this payload on any Data Extension. Thanks !

EDIT : my customActivity.js

define(function (require) {
var Postmonger = require('postmonger');
var connection = new Postmonger.Session();
var payload = {};
var steps = [
    {'key': 'eventdefinitionkey', 'label': 'Event Definition Key'}
];

//HERE it works 
//connection.trigger('requestSchema');

var currentStep = steps[0].key;
var deName;
$(window).ready(function () {
    connection.trigger('ready');
});

function initialize(data) {
    if (data) {
        payload = data;
    }
}

function onClickedNext() { //SAVE USED HERE
    if (currentStep.key === 'eventdefinitionkey') {
        save();                       
    } else {
        connection.trigger('nextStep');
    }
}

function onClickedBack () {
    connection.trigger('prevStep');
}

function onGotoStep (step) {
    showStep(step);
    connection.trigger('ready');
}

function showStep (step, stepIndex) {
    if (stepIndex && !step) {
        step = steps[stepIndex - 1];
    }

    currentStep = step;

    $('.step').hide();

    switch  (currentStep.key) {
    case 'eventdefinitionkey':
        $('#step1').show();
        $('#step1 input').focus();
        break;
    }
}



function save() { //SAVE FUNCTION
    console.log('save');
    connection.trigger('requestSchema'); //NOT SHOWN IN CONSOLE

    let campaignNameKey = $('#select-campaign-name').val();
    let csvName = $('#select-csv-name').val();

    console.log("DE NAME " + deName);
    payload['arguments'] = payload['arguments'] || {};
    payload['arguments'].execute = payload['arguments'].execute || {};

    payload['arguments'].execute.inArguments = [{
        'campaignNameKey': campaignNameKey,
        'csvName': csvName,
        "Prenom": "{{Contact.Attribute."+ deName +".[\"Prénom\"]}}",
        "Nom": "{{Contact.Attribute." + deName +".Nom}}",
        "Mobile": "{{Contact.Attribute." + deName +".Mobile}}",
        "Campagne": "{{Contact.Attribute." + deName +".Campagne}}",
        "stopSMS": "{{Contact.Attribute." + deName +".stopSMS}}"
    }];

    payload['metaData'] = payload['metaData'] || {};
    payload['metaData'].isConfigured = true;
    //console.log(JSON.stringify(payload));
    connection.trigger('updateActivity', payload);
}

connection.on('requestedSchema', function (data) {    //CONNECTION ON
    // save schema
    console.log('*** Schema ***', JSON.stringify(data['schema']));
    let schema = JSON.stringify(data['schema']);
});
connection.on('initActivity', initialize);
connection.on('clickedNext', onClickedNext);
connection.on('clickedBack', onClickedBack);
connection.on('gotoStep', onGotoStep);
});

3 Answers 3

10

You can use undocumented 'requestSchema' Postmonger event to retrieve schema of event data source:

connection.trigger('requestSchema');

Than use response from Journey Builder:

connection.on('requestedSchema', function (data) {
   // save schema
   console.log('*** Schema ***', JSON.stringify(data['schema']));
});

Extract relevant information and save it in inArguments.
Example of schema:

[{
    "key": "Event.APIEvent-cbf6ce98-ba4f-a5c1-cc68-503ca1f60c39.Id",
    "type": "Text",
    "length": 18,
    "default": null,
    "isNullable": null,
    "isPrimaryKey": null
}, {
    "key": "Event.APIEvent-cbf6ce98-ba4f-a5c1-cc68-503ca1f60c39.Name",
    "type": "Text",
    "length": 50,
    "default": null,
    "isNullable": null,
    "isPrimaryKey": null
}, {
    "key": "Event.APIEvent-cbf6ce98-ba4f-a5c1-cc68-503ca1f60c39.Mobile",
    "type": "Text",
    "length": 50,
    "default": null,
    "isNullable": null,
    "isPrimaryKey": null
}]
9
  • Thanks a lot that was exactly what I've been searching for ! :) I will ask you a further question if you don't mind : Can I get the colmns names of a Data Extension with those kind of trigger ? And if possible which one ?
    – Otor
    Jun 19, 2018 at 8:00
  • Event.APIEvent-cbf6ce98-ba4f-a5c1-cc68-503ca1f60c39.Id in my solution Id is a column name, so you need just extract this data from the schema. Jun 19, 2018 at 8:28
  • I edited the question and there is the answer of requestedSchema, I don't see the same structure of JSON as you have
    – Otor
    Jun 19, 2018 at 8:38
  • 1
    My bad mate ! It was just that I was not seeing the good thing because of Journey Builder and the save feature that didn't take the correct customActivity.js thanks a lot !
    – Otor
    Jun 19, 2018 at 9:12
  • I am using API Event as entry source, so i have different schema Jun 19, 2018 at 9:27
6

You can use requestedTriggerEventDefinition Postmonger event, it will return a schema that will return information about the Journey builder(Name,dataExtensionId,...) to you.

You need the field eventDefinitionKey and use it instead of your data extension 'Contacts'.

Here is an example of what it would be like

var eventDefinitionKey;
connection.trigger('requestTriggerEventDefinition');

connection.on('requestedTriggerEventDefinition',
function(eventDefinitionModel) {
    if(eventDefinitionModel){

        eventDefinitionKey = eventDefinitionModel.eventDefinitionKey;
        console.log(">>>Event Definition Key " + eventDefinitionKey);
        /*If you want to see all*/
        console.log('>>>Request Trigger', 
        JSON.stringify(eventDefinitionModel));
    }

});

And then in function save :

payload['arguments'].execute.inArguments = [{
    'campaignNameKey': campaignNameKey,
    'csvName': csvName,
    "Prenom": "{{Contact.Attribute."+ eventDefinitionKey+".\"Prénom\"}}",
    "Nom": "{{Contact.Attribute." + eventDefinitionKey+".\"Nom\"}}",
    "Mobile": "{{Contact.Attribute." + eventDefinitionKey+".\"Mobile\"}}",
    "Campagne": "{{Contact.Attribute." + eventDefinitionKey 
    +".\"Campagne\"}}",
    "stopSMS": "{{Contact.Attribute." + eventDefinitionKey +".\"stopSMS\"}}"
}];
2

You may also use requestInteraction which is part of the Postmonger events.

var eventDefinitionKey;
connection.trigger('requestInteraction');

connection.on('requestedInteraction', function(settings){
    eventDefinitionKey = settings.triggers[0].metaData.eventDefinitionKey;
});

So in your function save you can use the eventDefinitionKey variable to reference to your entry source DE

payload['arguments'].execute.inArguments = [{
  "campaignNameKey": campaignNameKey,
  "csvName": csvName,
  "Prenom": "{{Event."+ eventDefinitionKey +".Prenom}}",
  "Nom": "{{Event."+ eventDefinitionKey +". Nom}}",
  "Mobile": "{{Event."+ eventDefinitionKey +". Mobile}}",
  "Campagne": "{{Event."+ eventDefinitionKey +". Campagne}}",
  "stopSMS": "{{Event."+ eventDefinitionKey +". stopSMS}}"
}];

For more information:

Postmonger Events Reference

2
  • Hey man! can you help me on this, I tried your solution & did not work : salesforce.stackexchange.com/questions/372479/…
    – TaouBen
    Mar 27 at 11:57
  • I tried to execute the requestInteraction to get the defintion key, and used the CONTACT object to get my rows fields from the DE using CONTACT.ATTRIBUTE.DE_NAME but now, I replaced the DE_NAME with the defintion key & it is not correct, is there a way I can retirieve the DE name ?
    – TaouBen
    Mar 27 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.