To display the single row array data into multiple rows in Read-only grid.

Certified Associate Developer

Hi Team,

I want to display the single row of array data into multiple rows in read only grid. pls find the below screenshot.  

one invoice reference number multiple order items in database, but i want to display one invc numer and one order item 1 row. Again, same invc number second value vale of order item number 2 different row. pls refers first row data.

Thanks,

Nagesh   

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hello  

    below is something that will help you to understand how to achieve your requirement. Please replace with your values and fields accordingly to try out.

    a!localVariables(
    local!data:yourDataHere,
      local!formatData: a!flatten(
        a!forEach(
          items: local!data,
          expression: a!localVariables(
            local!rowData: fv!item,
            a!forEach(
              items: fv!item.itemId,
              expression: a!map(
                invoice: local!rowData.invoice,
                itemId: fv!item,
                billedQuantity: index(
                  local!rowData.billedQuantity,
                  wherecontains(fv!item, local!rowData.itemId),
                  null
                )
              )
            )
          )
        )
      ),
      {
        a!gridField(
          label: "Original Data",
          data: local!data,
          columns: {
            a!gridColumn(label: "Invoice", value: fv!row.invoice),
            a!gridColumn(label: "Item Id", value: fv!row.itemId),
            a!gridColumn(
              label: "Billed Quantity",
              value: fv!row.billedQuantity
            )
          }
        ),
        a!gridField(
          label: "Formatted Data",
          data: local!formatData,
          columns: {
            a!gridColumn(label: "Invoice", value: fv!row.invoice),
            a!gridColumn(label: "Item Id", value: fv!row.itemId),
            a!gridColumn(
              label: "Billed Quantity",
              value: fv!row.billedQuantity
            )
          }
        )
      }
    )

    Also I would say, the way you are saving your data is not a preferable format. This would cause you troubles when displaying the data or while trying to update the data.

    I would suggest iterate each item before you save and have a new row of data with same invoice number.

Reply
  • 0
    Certified Senior Developer

    Hello  

    below is something that will help you to understand how to achieve your requirement. Please replace with your values and fields accordingly to try out.

    a!localVariables(
    local!data:yourDataHere,
      local!formatData: a!flatten(
        a!forEach(
          items: local!data,
          expression: a!localVariables(
            local!rowData: fv!item,
            a!forEach(
              items: fv!item.itemId,
              expression: a!map(
                invoice: local!rowData.invoice,
                itemId: fv!item,
                billedQuantity: index(
                  local!rowData.billedQuantity,
                  wherecontains(fv!item, local!rowData.itemId),
                  null
                )
              )
            )
          )
        )
      ),
      {
        a!gridField(
          label: "Original Data",
          data: local!data,
          columns: {
            a!gridColumn(label: "Invoice", value: fv!row.invoice),
            a!gridColumn(label: "Item Id", value: fv!row.itemId),
            a!gridColumn(
              label: "Billed Quantity",
              value: fv!row.billedQuantity
            )
          }
        ),
        a!gridField(
          label: "Formatted Data",
          data: local!formatData,
          columns: {
            a!gridColumn(label: "Invoice", value: fv!row.invoice),
            a!gridColumn(label: "Item Id", value: fv!row.itemId),
            a!gridColumn(
              label: "Billed Quantity",
              value: fv!row.billedQuantity
            )
          }
        )
      }
    )

    Also I would say, the way you are saving your data is not a preferable format. This would cause you troubles when displaying the data or while trying to update the data.

    I would suggest iterate each item before you save and have a new row of data with same invoice number.

Children