0

Does anyone have any clever ways to execute SSJS from within a journey? I have some ideas but would love to hear yours. My use case is to listen for new Salesforce CRM records to be created. When they're created, kick off the journey - all that's fine, we can do that through Salesforce Data entry event. But, what I want to do is when a new record is created to make an SSJS call to pull out a specific URL within a field on that object, make an external API call to Rebrandly to shorten the URL and update the object. I should be able to do this by mocking up an email and including AMPScript in that email to make an HTTPGet call to a CloudPage, and on the CloudPage I'll do my SSJS work. But, it's real hacky. I would have to basically write the AMPScript and then after the HTTPGet call, do a RaiseError() to cancel out of the email send. Oh, and choose a dummy email address that the journey will "send to". Does anyone have any other "better" ways to do this?

1
  • 1
    I would do exactly what you said, but instead of RaiseError (which you would get charged for) I would put something like 1 == 1 in the exclusion script box for that email activity to cancel the send (which you won’t get charged for) – zuzannamj Nov 5 '20 at 20:08
3

There isn't a great way to do this. The best approach would be to build a custom activity, but the following approach should work:

Create a script activity containing your SSJS and save it as a code snippet*, with the following code:

<script runat="server">
Platform.Load("Core","1");

// insert your script here

Write(1); // outputs 1 for exclusion script
</script>

Next, add a Send Email Activity to your journey that just uses an empty email, but you might want to include %%[RaiseError('do not send!')]%% in the email just to be absolutely certain that the email is not sent under any circumstances (for example, if someone accidentally deletes Write(1); in the code snippet).

Now, in the exclusion script field of the Send Email Activity, enter the following:

TreatAsContent(ContentBlockByKey("insert-code-snippet-external-key"))==1

This will force the SSJS in the code snippet to be intepreted, and as it always return 1, the email won't be sent.

*Note: use a code snippet over another content block type, as all other content blocks are wrapped in HTML tables.

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.