1

I am quite new for custom activity.

I am unable to understand , how custom activity runs, when we activated journey what would be the method that will execute the method.

Can we segregate the code on the basis of journey status, Actually we want to insert some data from iframe before the journey is activated and once the journey is activated , I want to fetch the data from data extension and create a JSON with journey data and send that JSON to third party server using REST API

Can anyone help me to understand the flow of custom activity.

Thanks

1
  • I'm not sure where the iFrame comes in, but the various routes in your app like publish, validate and stop are hit by Journey Builder with an http request when your Journey Builder Interaction passes through the various statuses. The execute route is requested for each subscriber that passes though the Journey and hits your custom activity. Could you elaborate a bit on segregating your code based on journey status? – Macca Apr 16 '20 at 13:36
2

You can insert some data from the iframe before the journey is activated by saving data inputs in the config.js - inArguments. When you click "Done" in the iframe, the Postmonger event connection.on('clickedNext', save) will be fired and you can save the inputs:

customActivity.js

function save() {
    var message = $('#idMessage').val();

    payload['arguments'].execute.inArguments = [{
        "tokens": authTokens,
        "smsMessage": message,
        "phone":"{{Contact.Attribute." + '\"' + eventDefinitionKey + '\"' + ".\"Contact:MobilePhone\"}}",
        "key":"{{Contact.Key}}"
    }];

    payload['metaData'].isConfigured = true;
    connection.trigger('updateActivity', payload);
}

Once the journey is activated, the Execute function will run and there you can get your inputs from the inArguments.

server.js

app.post('/journeybuilder/execute', (req, res) => {
    verifyJwt(req.body, Pkg.options.salesforce.marketingCloud.jwtSecret, (err, decoded) => {
        //verification error -> unauthorized request
        if (err) {
            console.error(err);
            return res.status(401).end();
        }
        
        if (decoded && decoded.inArguments && decoded.inArguments.length > 0) {

                var phone = decoded.inArguments[0].phone;
                var message = decoded.inArguments[0].smsMessage;
                var data = { 
                        auth_id: 'xxxxxxx',
                        auth_secret: 'xxxxxxxx',
                        message: message,
                        phone: phone };
                sendSms (data);
                
        } else {
            console.error('inArguments invalid.');
            return res.status(400).end();
        }
    });
    return res.status(200).json({success: true});
});

If you want to use data coming from your data extension you can use merge fields:

8
  • Thank you for valuable answer but I am bit confuse in between EventDefinationKey and **Data extension Name **. can you please explain which one is better approach. – Vasudha Tandon Apr 23 '20 at 5:50
  • approach.payload['arguments'].execute.inArguments = [{ "tokens": authTokens.token, "Email": "{Contract.Attribute.DE_Name.Email}", "Contactkey": "{{Contract.Attribute.DE_Name.ContactId}}", "MessageSubject": messagesubject, "MessageBody": messagebody, "dateSent": dateTime }]; payload['metaData'].isConfigured = true; console.log('payload------'+payload.inArguments) connection.trigger('updateActivity', payload); – Vasudha Tandon Apr 23 '20 at 5:59
  • @Brian Miller , please refer the mentioned above comments – Vasudha Tandon Apr 23 '20 at 7:31
  • If you want to get the Data Extension in a generic way, meaning that any data extension created will automatically suit this field you can do it by getting the EventDefinationKey by adding this in your custom activity: connection.on('requestedTriggerEventDefinition', setEventDefinitionKey) and in the onrender function:connection.trigger('requestTriggerEventDefinition') don't forget to edit your field as well:"phone":"{{Contact.Attribute." + '\"' + eventDefinitionKey + '\"' + ".\"Contact:MobilePhone\"}}", – Blue Cap Apr 23 '20 at 7:59
  • the EventDefinitionKey function will have this inside: if(eventDefinitionModel){ eventDefinitionKey = eventDefinitionModel.schema.name; } – Blue Cap Apr 23 '20 at 8:03

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.