Best way to compare two array of CDT and remove duplicates based on certain fields?

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:

{
type!example(

email: "hello@gmail.com",

type: 1,

date: 01/01/2022

),

type!example(

email: "hello11@gmail.com",

type: 1,

date: 03/02/2023

),

type!example(

email: "hello@gmail.com",

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

Parents Reply
  • +1
    Appian Employee
    in reply to walkers

    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
        )
      )
    )

Children