Automate file resources upload with a workflow

Adobe Campaign, Marketing Automation
2 minutes read

Sometimes, you will reach a point where you want to upload file resources from a script. Although there are hints on the Experience League, even with those, this problem has caused me some troubles.

However, challenges and troubles are what I seek. I have decided to map this functionality, which can become handy once in a blue moon. For example you want to attach dynamic attachments to recipient delivery or add before made qr codes or vouchers to the email content.

For those seeking a quick answer without delving into this blog, the solution lies within the nms:assetIntegration.js JavaScript library. Check out the method call uploadContentToCampaign for the answer you’re looking for.

Building technical workflow

We can set up a technical workflow that triggers every xy minutes to check for the existence of a file in a remote folder. If the file exists, we will load it into Adobe Campaign. The actual file, along with its path, is automatically saved for us in the workflow variables vars.filename.

Adobe Campaign Classic - autoamtivally upload file resources

For this purpose we will use File transfer activity. Where first will be set to Test to see if file exists and second to File download. After we process file with the workflow we add JavaScript activity to save and publish our file

Adobe Campaign Classic - upload resource workflow setup
Saving and publishing file

Last but not least is the step where we save the file loaded with File transfer activiry as resources and publish them to the vast internet. There are Experience League community posts discussing this topic, especially the issues with publishing resources. However, for my recent endeavor, none of those—many of which were my own—hints helped.

var fileName,
    uploadPath = (application.instanceVarDir + "/upload/").toString(),
    patternRemoveTimestamp = /_\d{14}[a-z]/;

String.prototype.getFileExtension = function() {
  // Regular expression to match the file extension
  var regex = /(?:\.([^.]+))?$/,
      extension = regex.exec(this)[1];
  return extension ? extension.toLowerCase() : null;

fileName = (vars.filename).toString().split("/").pop();
fileExtension =  fileName.getFileExtension();
fileName = fileName.replace(patternRemoveTimestamp, "");
md5FileName = digestStrMd5(fileName);

file = new File(vars.filename);
  logWarning('File' + vars.filename + " is missing");
} else {
  if(file.copyTo(uploadPath + md5FileName + "." + fileExtension)){
    fileRes = NLWS.xtkFileRes.create();
    fileRes.storageType = 5;
    fileRes.useMd5AsFilename = 1;
    fileRes.publish = true;
    fileRes.userContentType = 0;
    fileRes.label = fileName;
    fileRes.folder_id = 11111;
    fileRes.md5 = md5FileName;
    fileRes.fileName = md5FileName + "." + fileExtension;
    fileRes.originalName = md5FileName + "." + fileExtension;  
    logInfo('uploaded file:' + fileName);
  1. String Prototype Extension:
    • Added getFileExtension method to the String prototype to extract file extensions.
  2. Filename and Extension Extraction:
    • Extracted the filename from vars.filename.
    • Extracted the file extension using the custom getFileExtension method.
  3. Timestamp Removal and MD5 Hashing:
    • Removed the timestamp from the filename using a regular expression.
    • Generated an MD5 hash of the modified filename.
  4. File Handling, upload and publish:
    • Checked if the specified file exists.
    • Copied the file to the upload path with the new filename (MD5 hash + original file extension).

The difference between the code that is online and the code found in the library is the function called WebPostUpload, which, by its JSAPI definition, ‘finalizes the storage of the resource after the upload (from a web page) to the server depending on the storage type used. It recovers the codepage and the content type. I will try to use it without next.

What I need to explore is the possibility of using human-readable text as a filename, as it seems that only an MD5 hash can be used in naming. When I used human-readable text as the filename, the process froze, and I had to kill the workflow.

Salesforce Marketing Cloud Tips
Journey builder, Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Refresh Delivery in Transactional Journey

1 minute read

The process might seem straightforward at first glance—simply refreshing the email delivery content in Salesforce Marketing Cloud should suffice to receive the updated email contents. However, there’s more to consider. Salesforce Marketing Cloud utilizes server-side caching, which may display outdated content. Understanding when the cache refreshes isn’t always clear. In scenarios where immediate changes are […]

Continue reading
Salesforce Marketing Cloud Tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

How to refresh data extension records

1 minute read

You might have noticed that records are not refreshed automatically, which makes sense. However, there is no refresh button. Here are some helpful tips I’ve discovered on how to refresh records within the data extension while it’s open. Email studio In email studio it is failry easy you simply navigate to another folder and return […]

Continue reading
Adobe Campaign Classic tips
ACC Tips & Tricks, Adobe Campaign, Marketing Automation

Add content variation to the proof subject

1 minute read

When dealing with multiple variants defined within one delivery template featuring dynamic content blocks, stakeholders most likely want to see proofs for each variant. To enhance readability in their mailbox, I tend to add the email variant to the subject line. A simple solution, similar to what we shown you when using salesforce marketing cloud […]

Continue reading
Top 5 SFMC tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

The Top 5 Stress-Busting Tips I have Learnt

3 minutes read

Working with any marketing automation platform, especially Salesforce Marketing Cloud, can provide a great user experience and a sense of accomplishment. However, it can also entail many stressful hours dedicated to solving seemingly easy issues. Here are my top 5 tips that made my daily work less stressed and saved me lots of cursing this […]

Continue reading
Salesforce Marketing Cloud Tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Use client-side JavaScript in content block

1 minute read

Recently, I attempted to reference a content block from a cloud page that contained client-side JavaScript, and to my surprise, Salesforce Marketing Cloud removed it entirely. It looks like certain hook that triggers when you save your content block doesn;t like client side scripts and are completely removed like comments are when a executable program […]

Continue reading
Adobe Campaign Classic tips
ACC Tips & Tricks, Adobe Campaign, Marketing Automation

Proof Email Template for Multiple Variants

1 minute read

Imagine having to proof all the possible variants of a delivery template, where there could be numerous end variations. How can we effectively proof such an email template? There is a simple yet powerful workaround for proofing all the variants, and here’s how to achieve it: Moreover, to differentiate between variations, you can include your […]

Continue reading
Salesforce Marketing Cloud Tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

How to utilize polyfill functions in SFMC

1 minute read

Development in Salesforce Marketing Cloud’s SSJS can be very restrictive, especially when you’re already familiar with the latest EcmaScript6 JavaScript features. We can’t use object spreading or curly bracket functions {}=>() and many, many more. However, we can introduce certain very helpful functions that don’t exist in older versions of JavaScript. The way we do […]

Continue reading
Salesforce Marketing Cloud Tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Cannot add attributes to data extension

less than a minute read

Occasionally, as a Salesforce Marketing Cloud administrator, lurker, practitioner, or bystander, you encounter a seemingly simple yet potentially time-consuming task—adding attributes to a data extension. While it may sound straightforward, the process is not always as simple as it appears. When adding or editing data extension attributes in Salesforce Marketing Cloud, you may face a […]

Continue reading
Adobe Campaign Classic tips
ACC Tips & Tricks, Marketing Automation

Fix delivery template error in Alert activity

1 minute read

Sooner or later, you will be tasked with creating alert notifications in Adobe Campaign Classic. Technical notifications are very useful, especially for monitoring technical processes. Alert notifications can be used to notify certain groups or operators when, for example, there was no file on SFTP or a particular marketing campaign has not had any recipients […]

Continue reading