Getting data group by field and the latest one

Certified Lead Developer

Hi Champs,

I need to fetch only unique value from a dictionary with the latest data. Below is the sample of the output

Here you can see color highlighted ones are same value of training name. So instead of 5 dictionary I want only 3 with unique training name . For unique data I want to fetch the latest of duplicate data.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    Hello  ,
    I think this piece of code can fetch the latest of the duplicate data.

    a!localVariables(
      local!data: {
        {
          trainigNotes: "testt",
          trainingDoc: 48195,
          trainingName: "SPPT1",
          id: 2,
          hcpId: 4
        },
        {
          trainigNotes: "testingDoubtData",
          trainingDoc: 48196,
          trainingName: "SPPT1",
          id: 3,
          hcpId: 4
        },
        {
          trainigNotes: "unique",
          trainingDoc: 132595,
          trainingName: "SPPT5",
          id: 8509,
          hcpId: 4
        },
        {
          trainigNotes: "cep2",
          trainingDoc: 132594,
          trainingName: "SPPT2",
          id: 8510,
          hcpId: 4
        },
        {
          trainigNotes: "cep1",
          trainingDoc: 132593,
          trainingName: "SPPT2",
          id: 8511,
          hcpId: 4
        },
    
      },
      local!trainingNames: index(local!data, "trainingName", ""),
      local!uniqueNames: union(local!trainingNames, local!trainingNames),
      local!indexes: a!forEach(
        items: local!uniqueNames,
        expression: index(
          wherecontains(
            fv!item,
            touniformstring(index(local!data, "trainingName", ""))
          ),
          1,
          {}
        )
      ),
      index(local!data, local!indexes, {})
    )

Reply
  • 0
    Certified Associate Developer

    Hello  ,
    I think this piece of code can fetch the latest of the duplicate data.

    a!localVariables(
      local!data: {
        {
          trainigNotes: "testt",
          trainingDoc: 48195,
          trainingName: "SPPT1",
          id: 2,
          hcpId: 4
        },
        {
          trainigNotes: "testingDoubtData",
          trainingDoc: 48196,
          trainingName: "SPPT1",
          id: 3,
          hcpId: 4
        },
        {
          trainigNotes: "unique",
          trainingDoc: 132595,
          trainingName: "SPPT5",
          id: 8509,
          hcpId: 4
        },
        {
          trainigNotes: "cep2",
          trainingDoc: 132594,
          trainingName: "SPPT2",
          id: 8510,
          hcpId: 4
        },
        {
          trainigNotes: "cep1",
          trainingDoc: 132593,
          trainingName: "SPPT2",
          id: 8511,
          hcpId: 4
        },
    
      },
      local!trainingNames: index(local!data, "trainingName", ""),
      local!uniqueNames: union(local!trainingNames, local!trainingNames),
      local!indexes: a!forEach(
        items: local!uniqueNames,
        expression: index(
          wherecontains(
            fv!item,
            touniformstring(index(local!data, "trainingName", ""))
          ),
          1,
          {}
        )
      ),
      index(local!data, local!indexes, {})
    )

Children
No Data