Removing duplicate objects

A limitation of the List Helpers remove duplicates function is that it can only remove simple items from an array, and it can't remove objects based on a particular field in that object being unique.

For example you may have just fetched an array of message objects from Data Storage (you might have created this array by setting the data with the 'Append to list' operation and then used the 'Get value' function to call your message list), which you want to make unique by their ticket_url:

📋
1
{
2
"value": [
3
{
4
"attachment_text": "Support: hello there! I need some help syncing records",
5
"ticket_url": "https://mycompany.zendesk.com/agent/tickets/1537",
6
"ticket_text": "Ticket 1537 from ronburgundy@news.com"
7
},
8
{
9
"attachment_text": "Copied from original request - 401 unathorized",
10
"ticket_url": "https://mycompany.zendesk.com/agent/tickets/1459",
11
"ticket_text": "Ticket 1459 from klaus.kinsky@kinsky.com"
12
},
13
{
14
"attachment_text": "Hi There, I can't access my stuff",
15
"ticket_url": "https://mycompany.zendesk.com/agent/tickets/1536",
16
"ticket_text": "Ticket 1536 from gretchen.mol@mol-shopping.com"
17
},
18
{
19
"attachment_text": "Hi Team - we need to process multiple records",
20
"ticket_url": "https://mycompany.zendesk.com/agent/tickets/1564",
21
"ticket_text": "Ticket 1564 from roger@ramjet.com"
22
},
23
{
24
"attachment_text": "Roger here, following up on my previous message",
25
"ticket_url": "https://mycompany.zendesk.com/agent/tickets/1564",
26
"ticket_text": "Ticket 1564 from roger@ramjet.com"
27
},
28
{
29
"attachment_text": "Help, I'm a bit stuck",
30
"ticket_url": "https://mycompany.zendesk.com/agent/tickets/1556",
31
"ticket_text": "Ticket 1556 from penelope@pitstop.com"
32
},
33
{
34
"attachment_text": "It all seems to be lost",
35
"ticket_url": "https://mycompany.zendesk.com/agent/tickets/1536",
36
"ticket_text": "Ticket 1536 from gretchen.mol@mol-shopping.com"
37
},
38
{
39
"attachment_text": "Hi, I need to process lots of data",
40
"ticket_url": "https://mycompany.zendesk.com/agent/tickets/1173",
41
"ticket_text": "Ticket 1173 from sophia@copolla.com"
42
},
43
{
44
"attachment_text": "Hello, we need to troubleshoot some problems",
45
"ticket_url": "https://mycompany.zendesk.com/agent/tickets/1591",
46
"ticket_text": "Ticket 1591 from pat@pending.com"
47
}
48
]
49
}

To do this we can use the uniqBy method with the Lodash Helper.

The Lodash uniqBy method requires 2 parameters:

  1. The array

  2. The field which should be unique

So if we have the above array of messages being returned by the storage-2 connector in our workflow we can use the following setup of the Lodash Helper to remove objects which contain the same ticket_url:

This will then remove tickets 1564 and 1536 from the above list of messages.