Skip to main content
Inspiring
July 15, 2021
Solved

Remove duplicate values in grid

  • July 15, 2021
  • 6 replies
  • 0 views

Hi All,

I have requirement where I need to remove consequent duplicate value while showing the data in grid.

i,e if values are: {"Requested", "Requested", "Pending","Sent For Approval","Approved","Pending","Approved","Approved"} the expected output is {"Requested", , "Pending","Sent For Approval","Approved","Pending","Approved"}

Here "Requested" and "Approved" are getting rejected as they are consequently occurring twice.

    Best answer by madhusudans0001

    Try this:

    a!localVariables(
      local!list: {
        "Requested",
        "Requested",
        "Pending",
        "Sent For Approval",
        "Approved",
        "Pending",
        "Approved",
        "Approved"
      },
      local!newList: reject(
        fn!isnull,
        a!forEach(
          items: local!list,
          expression: if(
            or(
              fv!index = 1,
              local!list[fv!index - 1] <> fv!item
            ),
            fv!item,
            null
          )
        )
      ),
      local!newList
    )

    Hope it helps.

    6 replies

    July 15, 2021

    Hi Gaurav,

    You can get unique list first and then pass that to Grid.

    EX:{1,2,3,4,1,4,5}

    try
    union({1,2,3,4,1,4,5},{1,2,3,4,1,4,5}) returns :{1,2,3,4,5}

    Inspiring
    July 15, 2021

    Hi Leela,

    Requirement is to remove two consecutive duplicates, not all duplicates 

    {"Requested", "Requested", "Pending", "Sent For Approval", "Approved", "Pending", "Approved", "Approved"} the expected output is {"Requested", "Pending", "Sent For Approval", "Approved", "Pending", "Approved"}

    stefanhelzle0001
    Brainy
    July 15, 2021

    You use reduce() to do this. Requires a helper function. They idea is:

    If last item in list equals new value, skip it, else append it.

    MAIN

    a!localVariables(
      local!values: {"Requested", "Requested", "Pending", "Sent For Approval", "Approved", "Pending", "Approved", "Approved"},
      reduce(
        rule!SSH_ReduceHelper(
          list:_,
          newValue:_
        ),
        {},
        local!values
      )
    )

    HELPER: Inputs: list(Array of Text), newValue(Text)

    if(
      index(reverse(ri!list), 1, "") = ri!newValue,
      ri!list,
      append(ri!list, ri!newValue)
    )

    madhusudans0001
    July 15, 2021

    Try this:

    a!localVariables(
      local!list: {
        "Requested",
        "Requested",
        "Pending",
        "Sent For Approval",
        "Approved",
        "Pending",
        "Approved",
        "Approved"
      },
      local!newList: reject(
        fn!isnull,
        a!forEach(
          items: local!list,
          expression: if(
            or(
              fv!index = 1,
              local!list[fv!index - 1] <> fv!item
            ),
            fv!item,
            null
          )
        )
      ),
      local!newList
    )

    Hope it helps.