Remove duplicates from an array and sort the list

Hi all,

We have a data table where the key field holds a list of brands and towns (in the format brand_town). I am trying to take this list, remove the "brand_" piece from the start and just get a list of all the towns.

I have been able to do this using the following Request and Response.

Request: -
{
"requestUrlTemplate": "/api/v2/flows/datatables/{dataTableId}/rows?pageSize=500&showbrief=false&sortOrder=ascending",
"requestType": "GET",
"headers": {
"Content-Type": "application/json",
"UserAgent": "PureCloudIntegrations/1.0"
},
"requestTemplate": "${input.rawRequest}"
}

Response: -
{
"translationMap": {
"Merk_Plaat": "$.entities[*].key"
},
"translationMapDefaults": {},
"successTemplate": "{ "Plaat" : $Merk_Plaat.replaceAll("Brand1_|Brand2_|Brand3_", "") }"
}

I am calling the Data Action from a script, and the results are added to a ListType variable which I use to populate a drop-down. This all works perfectly, but the problem I have is that some of the towns have multiple brands associated with them, so I am getting duplicate values in my drop-down. I also have the problem that once the brand name is removed, we have a list that is not sorted alphabetically any more (it has a sort order like: -

A...
B...
C...
...
Z...
A...
B...
C...
...
Z...
A...
B...
C...
...
Z...)

Is there a way for me to remove the duplicates (and then to sort the remaining values alphabetically)?

Any assistance would be gratefully received.

Not a direct answer but more a design question.

Why not have a separate table with valid Brands, and read that instead?

Hi Simon,
It's the towns that I'm interested in, rather than the brands.

I could have a table that just holds the towns, but that would then mean I would need to update 2 tables if a brand opened a location in a new town.

At the moment, when this happens, I need to add the "brand_town" to the existing table, along with all the other required information. I then need to manually add the new town to the drop-down list in the script, so it can be selected by an agent.

I was hoping to find a way to just update the existing table, in order to reduce the duplication of effort, but if it can't be done then I will continue to just update the dropdown in the script manually, rather than having another data table.

Thanks for the suggestion though! :slight_smile:

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.