Deploy workflow templates with JavaScript
Adobe Campaign is a powerful tool for creating and managing marketing campaigns. One of its most useful features is the ability to create automated workflows. In this post, we will walk you through the process of “spawning” workflows in Adobe Campaign.
What is spawning a workflow? And why and where we can it be useful in our Adobe Campaign instance?
Imagine a technical workflow that involves exporting daily data. Every night, we export the changes in all tracking and delivery logs that occurred on the previous day. If this workflow fails without detection, we may lose data from multiple days. Fixing the issue requires modifying the exporting process to retrieve only the missing data from past days, which can be a time-consuming and labor-intensive task. However, if we create a separate workflow for each daily export, we can quickly restart any failed workflow for a specific day without losing any data or halting the process due to a failure on one day.
Another scenario where separation of workflows can be beneficial is when dealing with a technical workflow that involves frequent signal activity, with multiple calls being made every minute. In such cases, the incoming calls are queued up, leading to significant processing delays. By directing each remote call to run in a separate workflow, we can potentially achieve a major improvement in processing speed.
To address these scenarios, one possible approach is to spawn a workflow using the JSAPI function NLWS.xtkWorkflow.Spawn(). By following the steps outlined below, you can create a more robust process and potentially improve the time it takes to process data.
Step 1: Create a Workflow Template
The first step is to create a workflow template that contains all the activities you want to perform after the signal activity. Instead of using a signal activity, use a start activity and change the name to something like “start00”. Set the execution folder somewhere where all the workflows will be dumped so you have them nicely separated and later we can remove them or resolve any errors.
Step 2: Add Initialization Script
Go into the initialization script and add the following code:
var initVars = "vars.myvar1='" + vars.myvar1 + "'\n;"+ "vars.myvar2='" + vars.myvar1 + "'\n;"; var workflowVars = <workflow label={"Process data " + formatDate(new Date,"- %4Y%2M%2D%02H:%02N:%02S")} <activities> <start name="start00"> <initScript>{initVars}</initScript> </start> </activities> </workflow>; NLWS.xtkWorkflow.spawn( 'someNameWorkflow', <workflow> <activities> <start name="start00"> <initScript></initScrip> </extern> </activities> </workflow> )
This code will create a new workflow every time the signal activity is triggered, with the initialization script set up as specified.
Step 3: Clean Up Service
After some time, you will end up with thousands of workflows. Ideally, you should create a clean-up service that will remove all workflows from the folder that are finished and last start time is more than 30 minutes. To do this, create another workflow scheduled to run every 30 minutes that calls the “Update Data” activity with the delete option. This will only keep all failed workflows for you to fix and restart, and workflows that are not older than 30 minutes.
Conclusion
In this post, we’ve shown you how to create automated workflows in Adobe Campaign. By following these steps, you can set up a system that will automatically create workflows based on a template, with the technical process logic, and clean up any completed workflows that are no longer needed. With this in place, you can save time and streamline your technical processes.
Let me know in the comments how did you used this method in your Adobe Campaign Instance?