Skip to main content
rishukumarg1965
June 12, 2025
Question

Validate the excel header

  • June 12, 2025
  • 2 replies
  • 0 views

implement an Appian Expression Rule that validates the sequence of header values, ensuring that:

  • The first value is "SAP Number",

  • The second value is "Qty",

  • The third to sixth values, if present, are "Spare", "Price", "Delivery Date", and "Remarks" ,

  • The third to sixth values are optional and may be missing,

    2 replies

    shubhama926776
    June 12, 2025

    You can read data from Excel files using the Excel Tools plugin and its associated smart services. For more information, please refer to the following resources:

    Excel Tools plugin documentation:  https://community.appian.com/b/appmarket/posts/excel-tools

    The attached documentation for additional details

    .[View:/cfs-file/__key/communityserver-discussions-components-files/11/readExcelByHeaders.pdf:320:240]

    yashwantha0914
    June 12, 2025

    Hi [mention:c7ed152842da4892ba88b9d946100b8f:e9ed411860ed4f2ba0265705b8793d05] 

    Use constant for storing the column names.
    I hope this is what you are expecting.

    a!localVariables(
      local!columnNames: {
        "SAP  Number",
        "Qty",
        "Spare",
        "Price",
        "Delivery Date",
        "Remarks"
      },
      local!excelDataSubset: readexcelsheetpaging(
        excelDocument: ri!excelDoc,
        sheetNumber: 0,
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 1)/*batchsize is 1 Because we need only first row from the excel to validate, which will be column names*/
      ),
      local!columnsNamesFromExcel: index(
        local!excelDataSubset,
        "data",
        "values",
        1,
        {}
      ),
      reject(
        a!isNullOrEmpty,
        a!forEach(
          items: local!columnNames,
          expression: if(
            contains({ 1, 2 }, fv!index),
            /*mandatory check for first two columns*/
            if(
              tostring(
                index(
                  local!columnsNamesFromExcel,
                  fv!index,
                  ""
                )
              ) = tostring(fv!item),
              null,
              concat(
                "Invalid header at A",
                fv!index,
                ", Expected header is '",
                fv!item,
                "' but it has: ",
                index(
                  local!columnsNamesFromExcel,
                  fv!index,
                  ""
                )
              )
            ),
            if(
              a!isNullOrEmpty(
                index(
                  local!columnsNamesFromExcel,
                  fv!index,
                  ""
                )
              ),
              null,
              if(
                tostring(
                  index(
                    local!columnsNamesFromExcel,
                    fv!index,
                    ""
                  )
                ) = tostring(fv!item),
                null,
                concat(
                  "Invalid header at A",
                  fv!index,
                  ", Expected header is '",
                  fv!item,
                  "' but it has: ",
                  index(
                    local!columnsNamesFromExcel,
                    fv!index,
                    ""
                  )
                )
              )          
            )
          )
        )
      )
    )