if duplicate data exists in the list then display a message indicating that duplicate data is present.

Certified Associate Developer

local!data: {
a!map(SAPNumber: "1111111", Qty: "1", Spare: "0"), 
a!map(SAPNumber: "1111111", Qty: "2", Spare: "1"),
a!map(SAPNumber: "1111111", Qty: "3", Spare: "0"),
a!map(SAPNumber: "2222222", Qty: "1", Spare: "0")
},

In the above list, If a duplicate combination of 'SAPNumber' and 'Spare' exists in the list, display a message indicating that duplicate data is present.

Example : 

a!map(SAPNumber: "1111111", Qty: "1", Spare: "0"), 

a!map(SAPNumber: "1111111", Qty: "3", Spare: "0"),

here, 'SAPNumber' and 'Spare' are same so it must shows a message.

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Senior Developer

    a!localVariables(
      local!data: {
        a!map(SAPNumber: "1111111", Qty: "1", Spare: "0"), 
        a!map(SAPNumber: "1111111", Qty: "2", Spare: "1"),
        a!map(SAPNumber: "1111111", Qty: "3", Spare: "0"),
        a!map(SAPNumber: "2222222", Qty: "1", Spare: "0")
      },
      
     a!forEach(
        items:local!data,
        expression:a!localVariables(
          local!innerData:index(local!data,fv!index,null()),
          local!SAPnumber:property(local!innerData,"SAPnumber"),
          local!spare:property(local!innerData,"Spare"),
          if(
            contains(
              property(remove(local!data,fv!index),"SAPnumber"),
              local!SAPnumber
            ),
            if(
              contains(
                property(remove(local!data,fv!index),"Spare"),
                local!spare
              ),
              "Duplicates Found",
              null()
            ),
            null()
           )
          )
        )
     )
    If the primary goal is to show a validation message when duplicates exist in the map list, Harsha's approach is effective. However, if identifying the precise position of each duplicate is required, this method would be more suitable. Feel free to adjust the code to fit your specific use case.

Reply
  • +1
    Certified Senior Developer

    a!localVariables(
      local!data: {
        a!map(SAPNumber: "1111111", Qty: "1", Spare: "0"), 
        a!map(SAPNumber: "1111111", Qty: "2", Spare: "1"),
        a!map(SAPNumber: "1111111", Qty: "3", Spare: "0"),
        a!map(SAPNumber: "2222222", Qty: "1", Spare: "0")
      },
      
     a!forEach(
        items:local!data,
        expression:a!localVariables(
          local!innerData:index(local!data,fv!index,null()),
          local!SAPnumber:property(local!innerData,"SAPnumber"),
          local!spare:property(local!innerData,"Spare"),
          if(
            contains(
              property(remove(local!data,fv!index),"SAPnumber"),
              local!SAPnumber
            ),
            if(
              contains(
                property(remove(local!data,fv!index),"Spare"),
                local!spare
              ),
              "Duplicates Found",
              null()
            ),
            null()
           )
          )
        )
     )
    If the primary goal is to show a validation message when duplicates exist in the map list, Harsha's approach is effective. However, if identifying the precise position of each duplicate is required, this method would be more suitable. Feel free to adjust the code to fit your specific use case.

Children