Expand my Community achievements bar.

We are excited to introduce our latest innovation to enhance the Adobe Campaign user experience — the Adobe Campaign v8 Web User Interface!
SOLVED

compare recipients in two or more lists in a worklow

Avatar

Level 4

Hi,

I have a workflow that needs to read two lists and compare their data. How can I do that ?

AFAIK, I can read a list in a javascript code but found no reference in documentation on how to compare it with another list.

/Regards

Kanwal

1 Accepted Solution

Avatar

Correct answer by
Level 10

Yes, This is possible in js activity.

Step one: Load every list in js context(Which you have mentioned you already achieved)

Step two:  comparison Part, Write a js function to compare list based on recipient Id.

//Below example will work, front end dev will be able to help you here to make it better

/****************************************************************************************************************************************************************

  Purpose: To compare two objects based on their Ids

* Returns List of common Ids in both list

****************************************************************************************************************************************************************/

var getCommonIdsfromTwoLists = function(objectlistA, objectListB) {

//var commonList = <recipient-collection><recipient/></recipient-collection>;

//use above if you need a collection, willhave to populate from the commonList object using another loop

var commonList = {};

for each(var rowA in objectlistB.recipient){

logInfo("rowA: " + rowA.@id.toString());

for each(var rowB in objectlistA.recipient){

logInfo("rowB: " + rowB.@id.toString());

// use this when you have same structure in ListA and List B to compare

// JSON.stringify(objectlistA) === JSON.stringify(objectlistB)

//use below for all other cases

if( rowA.@id.toString() == rowB.@id.toString()){

commonList[rowA.@id.toString()] = rowA.toString();

continue;

}

}

}

}

  return commonList;

}

Step 3: use this function recursively to get common Items from lists or modify this to suit your requirements.

Hope this helps!
Regards,

Amit

View solution in original post

5 Replies

Avatar

Level 10

Hi Kanwal,

If you want to compare the two lists, There can be multiple scenarios; I am going to assume that you are doing that for following cases:

  1. How many IDs are both in list A and B
  2. How many IDs are in A but not in B
  3. How many IDs are in B but not in A

Load your list in query or using file load activity, which allows you to manipulate them in workflow, Now choose your case for next step.

Case 1:

Use Intersection activity which allows you to keep only the elements common to the different inbound populations in the activity. This will give you common Ids in both lists.

Case 2:

Use Exclusion activity which is used to carry out additional filtering on inbound transition populations.

List A  will become primary set and List B becomes filtering set. List A and list B will be used as inbound transitions. Members of list B transitions will be excluded from the primary set. The outbound transition of the exclusion activity only contains the members of the primary set that were not encountered in the other inbound transitions.

Case 3:

Use Exclusion activity which is used to carry out additional filtering on inbound transition populations.

List B  will become primary set, and List A becomes filtering set. List A and list B will be used as inbound transitions. Members of list A transitions will be excluded from the primary set. The outbound transition of the exclusion activity only contains the members of the primary set that were not encountered in the other inbound transitions.

Hope this helps

Regards,

Amit

Avatar

Level 1

Thanks Amit,

I was wondering if there is a way to do it in a script.

I have a folder where input Lists will be available for workflow to read.

(Problem 1) : the actual number of lists is not fixed, so I can't use a union as union expects fixed set of lists in input.

(Problem 2) : There is a need to iterate over the list and apply exclusion on other lists based on specific the attributes values in the target population. AND do this to other lists

/Rgrds

Kanwal

Avatar

Correct answer by
Level 10

Yes, This is possible in js activity.

Step one: Load every list in js context(Which you have mentioned you already achieved)

Step two:  comparison Part, Write a js function to compare list based on recipient Id.

//Below example will work, front end dev will be able to help you here to make it better

/****************************************************************************************************************************************************************

  Purpose: To compare two objects based on their Ids

* Returns List of common Ids in both list

****************************************************************************************************************************************************************/

var getCommonIdsfromTwoLists = function(objectlistA, objectListB) {

//var commonList = <recipient-collection><recipient/></recipient-collection>;

//use above if you need a collection, willhave to populate from the commonList object using another loop

var commonList = {};

for each(var rowA in objectlistB.recipient){

logInfo("rowA: " + rowA.@id.toString());

for each(var rowB in objectlistA.recipient){

logInfo("rowB: " + rowB.@id.toString());

// use this when you have same structure in ListA and List B to compare

// JSON.stringify(objectlistA) === JSON.stringify(objectlistB)

//use below for all other cases

if( rowA.@id.toString() == rowB.@id.toString()){

commonList[rowA.@id.toString()] = rowA.toString();

continue;

}

}

}

}

  return commonList;

}

Step 3: use this function recursively to get common Items from lists or modify this to suit your requirements.

Hope this helps!
Regards,

Amit

Avatar

Employee Advisor

To add to the awesome response provided by Amit. Using JS to performing heavy processing can lead to exhaustion of allocated memory to JS interpreter.

There is a maxMB setting in serverConf.xml which by default is set to 64MB. So, if you are going to compare multiple lists with huge number of records, a good idea will be to get the maxMB increased to 512 MB.

If your instance is hosted by Adobe, please reach out to support for getting this done.

Regards,

VIpul

Avatar

Level 4

Thanks Amit & Vipul,

Amit_Kumar , Vipul Raghav

This is super useful & would work great

After some more deliberation on design with factors that mentioned here and some new requirements that we unearthed in the interim, we've decided to move to a different approach.

Appreciate the feedback though

/Regards

Kanwal