How can I show the data of two local variables into one grid

I am using two local variables and the data is coming via expression rules (there are multiple columns)

local!empStatus: index(rule!EO_getEmpStatus(),"data",{}),
local!empDetail: index(rule!EO_getEmpDetail(),"data",{})

I want to use the data of local!empStatus and local!empDetail into single read-only grid.

  Discussion posts and replies are publicly visible

  • It completely depends on whether the two queries return similar data types, but for example if both were identical, you could append the two arrays to each other and display the resulting data set.  Or rather, if the data dictionaries aren't identical but instead one of them offers more details on members of the other, then in your grid, you could index into the "detail" array for the current member of the "main" array, for example.  But without further detail as to what these queries pull, and what you want your grid to show, the only thing I or anyone else will be able to offer is this sort of blind guesswork.  Is there any further detail that you can provide?

  • Hi

    You can try something similar to this

    load(
      
      local!empStatus: {{id:3,status:"Active"}, {id:2, status:"Active"}, {id:1, status: "Inactive"}},
      local!empDetail: {{id:1,name:"ABC"}, {id:2, name:"PQR"}, {id:3, name: "LMN"}},
    
    a!formLayout(
      label:"Form",
      contents:{
        a!gridField(
          label:"Employee",
          totalCount: 3,
          columns: {
            a!gridTextColumn(
              label:"Name",
              data:local!empDetail.name
            ),
            a!gridTextColumn(
              label:"Status",
              data:a!forEach(local!empDetail,index(local!empStatus.status, wherecontains(fv!item.id,local!empStatus.id)))
            )
          },
          value: a!pagingInfo(startIndex: 1, batchSize: -1),
          saveInto: {},
          identifiers:local!empDetail.id
        )
      }
    )
    )

    But, as suggested by Mike, you can append the cdts in a local variable and then use that data subset. This will avoid the overuse of the looping function

  • Hi Mike,

    Thankyou for your time.

    rule!EO_getEmpStatus() is returning empId and status

    rule!EO_getEmpDetail()  is returning empId, firstName, lastName, band, group etc. fields.

    I want to show the data of following columns in my grid on the basis of empId: empId, firstName, lastName, status, band, group

    Regards,

    Ankita Singh

  • Hi ,

    Thankyou for the time.

    I have tried your scenario as well but i am getting an error as I want to use a!gridColumn (its a read only grid). 

    Regards,

    Ankita Singh

  • Hi Ankita,

    You can try any of the code between these 2.

    load(

    local!empStatus: {{id:3,empId:1,status:"Active"}, {id:2, empId:2, status:"Active"}, {id:1, empId:3, status: "Inactive"}},
    local!empDetail: {{id:1,name:"ABC"}, {id:2, name:"PQR"}, {id:3, name: "LMN"}},
    local!empFinaldata:a!foreach(
    items:local!empDetail,
    expression:{
    id:fv!item.id,
    name:fv!item.name,
    status:index(
    index(
    local!empStatus,
    wherecontains(
    tointeger(fv!item.id),
    tointeger(index(local!empStatus,"empId",{}))
    ),
    {}
    ),
    "status",
    {}
    )
    }
    ),
    a!formLayout(
    label:"Form",
    contents:{
    a!gridField(
    label:"grid",
    data:local!empFinaldata,
    pageSize:5,
    pagingSaveInto:fv!pagingInfo,
    columns:{
    a!gridColumn(
    label:"Name",
    value:fv!row.name
    ),
    a!gridColumn(
    label:"Status",
    value:fv!row.status
    )
    }
    )
    }
    )
    )

  • 2nd one 

    load(

    local!empStatus: {{id:3,empId:1,status:"Active"}, {id:2, empId:2, status:"Active"}, {id:1, empId:3, status: "Inactive"}},
    local!empDetail: {{id:1,name:"ABC"}, {id:2, name:"PQR"}, {id:3, name: "LMN"}},

    a!formLayout(
    label:"Form",
    contents:{
    a!gridField(
    label:"grid",
    data:local!empDetail,
    pageSize:5,
    pagingSaveInto:fv!pagingInfo,
    columns:{
    a!gridColumn(
    label:"Name",
    value:fv!row.name
    ),
    a!gridColumn(
    label:"Status",
    value:index(
    index(
    local!empStatus,
    wherecontains(
    tointeger(fv!row.id),
    tointeger(index(local!empStatus,"empId",{}))
    ),
    {}
    ),
    "status",
    {}
    )
    )
    }
    )
    }
    )
    )

  • Where exactly are you getting the error? The above code is also a read only field

  • 0
    Certified Senior Developer

    Hi ,

    Alternatively, you can also create a VIEW and join the 2 tables from which you are querying the data for empStatus and empDetail.

    This will be an efficient way because you can query all the required data in a single shot and also in the desired format.

  • FYI, if is on 19.2+, your code will produce an error as you're using the old (deprecated) paging grid component format, but not referring to it as its new name a!gridField_19r2.  I would suggest updating the code to reflect 19.2+, though, as it's a lot friendlier.

  • In general my best suggestion would be to create a database View which could merge the two source tables (i assume these are drawing their data from DB tables, anyway), as already mentioned by Nandhavi in another comment below - this will allow you to create a grid based on a single query of data where it's already a consolidated data set.