Iterating and calling custom functions for each record – AC Workflow

Many times we get stuck in situations where we have to perform a task for each record particularly when the default out-of-box functions provided by Adobe Campaign does not provide the required capability. The task could be anything like calling a third party or sending web request for each record with personalized data and capturing the responses from third party and back enriching our record set based on responses.  So, the ask is iterating through the records irrespective of targeting (Query, Read List, Union, Intersection, Split, Enrichment, Change dimension etc) and call that custom function for each record.

Another key important point to be taken care here, is the name of targeting schema itself which we have to iterate. The name could be generated dynamically or assigned on the run without being taken care of with proper naming convention. So, we need to do something flexible enough that it should not depend on the nomenclature of targeting schema.

Below are the basic steps that would help solving the problem here:

  1. Capturing the name of targeting schema that exists at previous step dynamically using variable vars.targetSchema.

    The variable schemaName assigned above plays a critical role as it will be used in steps ahead while iterating the records.
  2. Querying the record set received from previous targeting.
  3. Iterating the records, calling custom function and recording the responses.

    The method myCustomFunction() is the custom method which can be used to add custom behaviors. All the required parameters from targeting schema can be passed to this method and responses can be captured and stored in temprary table if required.
    The method processResponses() is iterating through the recordset and uses schemaName to fecth the value of each field in teh record.
  4. We can Save the result in a temporary table  and can later use it through enrichment to map back to targeting through primary key (@id in our case) and do further tasks in the workflow.
  5. Now, the last part is to call the consolidate these bits and pieces and call them to make it work.

So, finally the whole code would look something like this:

The workflow configuration for the use case is depicted as below: