I need to compare two lists of the same type of cdt, and remove any duplicates from one of the lists if two of the fields match. For example
CDT Array 1:
{type!example(
email: "hello@gmail.com",
type: 1,
date: 05/05/2019
)
}
CDT Array 2:
date: 01/01/2022
),
type!example(
email: "hello11@gmail.com",
date: 03/02/2023
type: 2,
date: 01/02/2023
In this example, I want to remove CDT 1 from CDT Array 2, because it is has the same email and ID fields as the CDT in CDT Array 1, and I want to return the other two CDTs in CDT Array 2.How can I do this as efficiently as possible?
Discussion posts and replies are publicly visible
You can use difference() function. In your case it will be difference(Array2,Array1).
Hope it works
Hi Bmsv, I don't think this will work because I only want to compare a few fields from each array of CDTS, not all the fields.
Would something like this work?
a!localVariables( local!one: { a!map( email: "hello@gmail.com", type: 1, date: 05 / 05 / 2019 ) }, local!two: { a!map( email: "hello@gmail.com", type: 1, date: 01 / 01 / 2022 ), a!map( email: "hello11@gmail.com", type: 1, date: 03 / 02 / 2023 ), a!map( email: "hello@gmail.com", type: 2, date: 01 / 02 / 2023 ) }, index( local!two, where( a!forEach( local!two, a!isNullOrEmpty( intersection( wherecontains(fv!item.email, local!one.email), wherecontains(fv!item.type, local!one.type) ) ) ), local!two ) ) )
That worked, thank you matthew.shutt