Adobe Campaign, Marketing Automation

Automate publishing file resources with workflow

Adobe Campaign Classic Automate Publishing File Resources With Workflow

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.

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

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(),
    md5FileName,
    fileExtension,
    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);
if(!file.exists){  
  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;  
    fileRes.WebPostUpload(<params/>);
    fileRes.PublishIfNeeded();
    fileRes.save();  
    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.

Oh hi there 👋
I have a FREE e-book for you.

Sign up now to get an in-depth analysis of Adobe and Salesforce Marketing Clouds!

We don’t spam! Read our privacy policy for more info.

#adobe campaign classic #JavaScript #programming #workflow
Marcel Szimonisz
Marcel Szimonisz
MarTech consultant As a marketing automation consultant, I specialize in solving problems, automating processes, and driving innovation in my clients' marketing platforms.

I hold certifications in Adobe Campaign v6 (3x certified) and Salesforce Marketing Cloud (5x certified).

Additionally, I serve as a community advisor for Adobe Campaign, offering expert insights and guidance.

In addition to my professional pursuits, I also enjoy exploring various programming languages, CMSs, and frameworks, further enhancing my technical expertise and staying at the forefront of industry advancements.
Take a look at our subscription offering in case you are looking for a Marketing Automation Consultant.

Leave a comment

Your email address will not be published. Required fields are marked *

Similar posts that you may find useful

Adobe Campaign post
Adobe Campaign, Marketing Automation

ACC | All about variables in Adobe Campaign

2 minutes read

In this article I will explain all sorts of variables you can come across when working with the tool. Also I will discuss different less known approach of storing variables. Workflow variables In adobe campaign we have way how to store variables between consecutive activities. Normally you would store variables as instance or context variables. […]

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

Troubleshooting issues with Data Extensions

1 minute read

There are other aspects that I find rather unknown; while there is likely a rational explanation, the platform doesn’t provide straightforward answers. Here are some learnings of mine while working with data extensions: Importing in Contact Builder throws a validation error on the date field. The same file has been successfully imported via Email Studio.

Continue reading
Salesforce Marketing Cloud Rant
Marketing Automation, Salesforce Marketing Cloud, SFMC Rant

SFMC RANT: Inline AMPScript mystery

3 minutes read

Working with Salesforce Marketing Cloud, I’ve learned that you often need to try different workarounds until you achieve the desired result. To succesfully solve problems, it all depends on your experience and patience. Recently, I did a significant amount of work with AMPScript and personalization and wrote many tips during these days. It seems that […]

Continue reading
ACC - How to JavaScript in Adobe Campaign Classic
Adobe Campaign, Marketing Automation

Master JavaScript in Adobe Campaign

7 minutes read

Adobe Campaign Classic utilizes JavaScript as the backend language for customizing various aspects of your instance, including workflows, libraries, web applications, and reports. The platform employs the Java Web Server called Tomcat for its operation. To execute JavaScript on the server, Adobe Campaign Classic utilizes a JavaScript engine called SpiderMonkey. SpiderMonkey, developed by the Mozilla […]

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

Refreshing Delivery Contents in Transactional Journeys

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