1

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);
});
5

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
}]
  • 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 ? – Pierre-Adrien Delisle Jun 19 '18 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. – Ros Haitovich Jun 19 '18 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 – Pierre-Adrien Delisle Jun 19 '18 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 ! – Pierre-Adrien Delisle Jun 19 '18 at 9:12
  • I am using API Event as entry source, so i have different schema – Ros Haitovich Jun 19 '18 at 9:27
4

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\"}}"
}];

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.