# How to merge two lists or dedup a list string in a reformat

**URL:** <https://forum.cloverdx.com/t/how-to-merge-two-lists-or-dedup-a-list-string-in-a-reformat/2135>\
**Category:** CloverDX Platform\
**Created:** [December 21, 2022, 7:25pm UTC](https://forum.cloverdx.com/t/how-to-merge-two-lists-or-dedup-a-list-string-in-a-reformat/2135 "2022-12-21T19:25:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelj](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@michaelj](https://forum.cloverdx.com/u/michaelj)\
**Post date:** [December 21, 2022, 7:25pm UTC](https://forum.cloverdx.com/t/how-to-merge-two-lists-or-dedup-a-list-string-in-a-reformat/2135/1 "2022-12-21T19:25:59Z")

</div>

I have two string fields that each has a list of states separated with semi-colons that I would like to combine into one field but without duplicating any of the states. For instance, the data coming into the reformat would looke like this:

RecordID LicensedStates LocationStates

100 PA;AZ;CA PA;AZ;AL

101 PA PA

102 AZ;CA CT

The result I would like to get out of the reformat would be:

RecordID CombinedStates

100 PA;AZ;CA;AL

101 PA

102 AZ;CA;CT

I’ve tried to find ways of doing this but after looking through the documentation for Normalizer, Denormalizer, and a few Java lines of code and just have no idea what i’m doing.

Any advice you have would be appreciated.

---

<div class="post-metadata">

**Author:** ![Alex\_Donnelly](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Alex\_Donnelly](https://forum.cloverdx.com/u/Alex_Donnelly)\
**Post date:** [December 27, 2022, 10:57am UTC](https://forum.cloverdx.com/t/how-to-merge-two-lists-or-dedup-a-list-string-in-a-reformat/2135/2 "2022-12-27T10:57:45Z")

</div>

Hi Michael,

Just use Map (former Reformat) component. You can apply transformation similar to this one:

//#CTL2  
string lLicensedStates ;  
string lLocationStates;

// Transforms input record into output record.  
function integer transform() {

//create lists of states from delimited input data  
lLicensedStates = $in.0.LicensedStates.split(“;”);  
lLocationStates = $in.0.LocationStates.split(“;”);

//iterate through LocationStates and check for each state presence in LicensedStates list  
foreach (string state : lLocationStates){  
if (! state.in(lLicensedStates)){  
lLicensedStates.append(state);  
}  
}

//convert list ot states into string, use “;” as delimiter  
string CombinedStates = join(“;”,lLicensedStates);

$out.0.RecordID=$in.0.RecordID;  
$out.0.CombinedStates=CombinedStates;

```
return ALL;  

```

}

It may not be the best performing way, but if your lists of states consit of only handful items, it will perform OK.

---

<div class="post-metadata">

**Author:** ![michaelj](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@michaelj](https://forum.cloverdx.com/u/michaelj)\
**Post date:** [December 28, 2022, 6:41pm UTC](https://forum.cloverdx.com/t/how-to-merge-two-lists-or-dedup-a-list-string-in-a-reformat/2135/3 "2022-12-28T18:41:46Z")

</div>

Thanks Alex. That worked perfectly.
