Automation Status Across Business Units

If you need to get a status snapshot of Automations across business units, here’s one way to go about it.

Add this code to a CloudPage in the parent business unit, update the mids array to include the desired values and publish.

You could also set something like this up in a Script Activity and write the results to a Data Extension for use in another process.

NOTE: As leto96 mentioned in the comments, CloudPages are public and should not be considered secure. Anyone with the URL can access it. Initial SSJS development is best done in a CloudPage, where you have a way to debug with output. Just be careful to unpublish or secure any utility/reporting type pages after you’re done.

Updating Salesforce Objects with Server-Side JavaScript

If the custom preference center in your integrated Marketing Cloud account needs to update Salesforce object attributes, you’re probably acquainted with the UpdateSingleSalesforceObject, RetrieveSalesforceObjects and CreateSalesforceObject AMPscript functions.

Well, if you’re like me and you’d rather build your custom preference center with Server-Side JavaScript (SSJS), then you’ll need a way to use these AMPscript-only functions. Here’s my general approach for wrapping the AMPscript function in SSJS:

One-Click Unsubscribe with AMPscript

Need to custom one-click unsubscribe landing page in AMPscript? Here’s how I generally code it:

This leverages the AMPscript API functions and mirrors the process you’d take if you were doing this with the Marketing Cloud SOAP API.


20190320 Update
If you’re having trouble finding the Publication ListIDs in your account, you can drop this bit of Server-Side JavaScript in your page. It’ll output a list of them.

Prune rows in a Data Extension with SSJS

Say you want to delete a million rows from a Data Extension in Salesforce Marketing Cloud (SFMC). Doing that with the SFMC Web Services can be a pain. One alternative is to utilize Server-Side JavaScript (SSJS) and a Landing Page.

I built a landing page that posts to itself and runs this pruneRows() function. I configured a Data Extension that contains the keys to delete. The script retrieves all of the rows with that key, deletes them and updates the DE of keys with the results.

You may have to experiment with the number of Row Keys to retrieve at a time. If the number is too high, the landing page will time-out. In my scenario, I found that processing 50 at a time worked well (line #8).

For further reading:

Retrieving and Starting an Automation with SSJS

Server-side Script (SSJS) Activities are a hidden gem of the Salesforce Marketing Cloud. They’re useful for a wide range of applications. I ran into a scenario where I wanted to run an Automation programmatically — if it’s not already running.

It was way harder than it needed to be. Hope this saves you some frustration:

The retrieve is for getting the ObjectID and Status of the Automation, which you then use to check to see if it’s running and then invoke a Perform if it isn’t.

The frustrating part of this was that the ObjectID is not a retrievable property of the Automation Object (unlike Status). It’s only returned in the result-set of a successful Retrieve.

I’d suggest testing this script in a Landing Page until you get it working and then move it to the Script Activity.

SFMC Support can enable Script Activities if there’s not a Script entry in the Interactions drop-down menu.

For further reading: