Skip to main content
May 2, 2024
Question

Read CSV file and want to find duplicate value

  • May 2, 2024
  • 11 replies
  • 0 views

Hi 

I need advice.

Read CSV file and want to find duplicate value.

if there are duplicate values .I want to display error msg..

I was able to load the CSV and remap it to the map list, but I was unable to check for duplicates values and unable to add error msg.

Image like the attached image

11 replies

daniell
Participating Frequently
May 2, 2024

Could you elaborate more on what you are trying to do? Are you looking for duplicates on "No" and/or "col1" and/or "col2"? What are you expecting in error1/2/3? What does your current expression rule look like, and what have you tried for finding the duplicate values that is giving you difficulty?

girlc0001Author
May 2, 2024

[mention:89ec515a02ff4fa28317edeb40cf0a4d:e9ed411860ed4f2ba0265705b8793d05] 

At first i want to read csv file and then check csv file data. I'm looking for duplicate value on [No] column.

if there are duplicate value on [No] column. i want to add error msg and sent it back csv file with error message.

If there  are no duplicate value register to DB. 

konduruc733182
May 2, 2024

Please find the below code. Made a sample code for your understanding. More efficient and simpler code can be created.

a!localVariables(
  local!doc: ri!doc,
  local!data: readexcelsheetpaging(
    excelDocument: ri!doc,
    sheetNumber: 0,
    pagingInfo: a!pagingInfo(startIndex: 2, batchSize: 5000)
  ).data.values,
  local!formatData: a!forEach(
    items: local!data,
    expression: if(
      a!isNullOrEmpty(fv!item[2]),
      {},
      a!map(
        name: fv!item[2],
        gender: fv!item[3],
        department: fv!item[4],
        tech: fv!item[5]
  )
  )
  ),
  local!duplicateCheck: a!forEach(
    items: local!formatData,
    expression: a!update(
      data: fv!item,
      index: "error",
      value: if(
        length(
          wherecontains(
            fv!item.name,
            local!formatData.name
          )
        )>1,
        "Duplicate Values Found",
        ""
      )
    )
  ),
  local!duplicateCheck
)