Does anybody know a way to filter/select only unique values of a certain field from a foreach statement via email scripting? I
We have different coverage type in addition to the Registration. The email has a table that includes the customer's Serial Number and Product Coverage combined into one row. The problem is that they are all part of the same object and the main registration and coverage are tied together via the same serial number, so this is creating more line items than we need.
So I'm trying to look for a way to just filter my list to only show unique Serial Numbers per line item.
can you show us:
I THINK I know what you're looking for, but I'm not 100% certain.
you also might want to review the solution in this thread (posted by you).
That might get you close.
Hi @Jo_Pitts1 , yeah I used that solution as my base and its got me close. I was able to get a list of all the asset type. A sample output is below for a customer is below. The first 2 rows is just what I want and then not show the red text rows. Because the serial number column and product protection share the same serialNumber. I would like to just only how unique value of serial numbers. I have another solution in place and forgot to save the code snippet for the below, but its inline basically with the code snippet from my previous post you listed above.
A sample output looks like this:
|Serial Number [type__c][serialNumber]||Limited Warranty [usageDate]||Product Protection [type_-c][usageDate]|
|ABCDEFG||10/21/21 - 12/21/24||Gold: 10/21/24-10/21/26|
|ZYXWVU||10/21/21 - 12/21/24||Plat: 10/21/24-10/21/26|
|ABCDEFG||10/21/21 - 12/21/24||Request a Quote|
|ZYXWVU||10/21/21 - 12/21/24||Request a Quote|
Is the list ordered?
i.e. once I've displayed a serial number, can I safely never display it again. Or are their other rules in place?
Yes, it is ordered by purchase date descending and it is filtered by just assets that were created yesterday. The duplicate serial numbers are being created when the customer has purchased a product coverage (which is always purchased after the original asset is created).
So in the table example I shared you'll never see the serial number more than twice.
So is this as simple as simply NOT displaying those records that have Request a Quote in Product Protection?
No that won't work because there could be case where the customer has an asset, but no product coverage and so they would just see that one. So this issue of duplicates serial number only happens when the customer has coverage
Sounds like you’re overcomplicating.
To display only one item for each unique String value of a certain property, make that property the unique key of a new map.
Now you have a map with one item for each unique value. Iterate over its values().
you beat me to it. I was going to say exactly the same thing, now we are down to the core requirement.