how to get the nested CDT Data

I have an Employee CDT and Documents CDT(One to many Relation Ship between them) documents table has foreign key empId ,i wanted to get the documents based on empId (foreign key)

if i write expression like

 a!queryEntity(
entity: cons!DOCUMENTS_DETAILS,
query: a!query(
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: - 1
),
filter: a!queryFilter(
field: "empId"( as foreign key in  documents table but empId field is not there  in Documents CDT),
operator: "in",
value:7
)
)
).data


so i am getting following error The field [empId] does not exist.. in such case how to get the nested CDT Data.

  Discussion posts and replies are publicly visible

  • Hi,

    If the Employee CDT has the nested CDT Document_Details, then fetch the details from Employee_Detail, you will get the Document_Details also.
  • Hi vinay,

    I wanted to display documents in paging grid.if i fetch documents through employee the total count as 1 because i am fetching through employee by passing empId

    a!queryEntity(
    entity: cons!EMPLOYEE_DATA,
    query: a!query(
    pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: - 1
    ),
    filter: a!queryFilter(
    field: "orgEmpId",
    operator: "=",
    value: ri!empId
    )
    )
    )
    o/p : startIndex: 1
    batchSize: -1
    sort: List of SortInfo: 1 item
    SortInfo
    field: "nationality"
    ascending: true
    totalCount: 1

    i have 3 documents for employee but if i fetch the documents through employee the total count as 1 while paging in grid i am getting following error

    a!gridField [line 24]: A grid component [label=“”] has an invalid value for “totalCount”. “totalCount” must not be null or less than the number of items in any of the “data” arrays, but “totalCount” was 1 and the largest column data array had 5 items.
  • hi kiran,

    a!queryEntity(

    entity: cons!EMP_DETAILS,(constant which refers employee entity )

    query: a!query(

    pagingInfo: a!pagingInfo(

    startIndex: 1,

    batchSize: - 1

    ),

    filter: a!queryFilter(

    field: "empId",

    operator: "in",

    value:7

    )

    )

    ).data

    by above entity you will get employee details

    then do index(local!employeeData,"documents",{})

    where local!employeeData (data from above query entity )

    documents is a filed name of nested cdt in employee table.

  • your employee data count is 1 but your documents count is multiple so,send the document count as total count to your grid(local!empData.documents )
  • You will have to do some juggling with the data here. Query both the tables seperatly then combine them per your requirement. If you want to show repeted rows with different document or best is to provide a link and on click show all the documents in a new section below.
  • Use total Count. This should resolve the issue.
  • Hi Kiran,

    If you are trying to use empId as a filter in your query, but there is no empId in the documents CDT (even if the DB table has the EMP_ID column), you will get this error message. If you add the empId field to the document CDT, the query should work fine. If you are trying to get information from the employee cdt by going through the document table first, I would recommend creating a DB view that has the relevant fields from both the document CDT and the employee CDT. Then you can create a query to call that view and query with both doc information and employee information and return both doc and employee info. using a!selection() in the query entity can also help you only pull back certain fields from the query if you wanted to do something like returning only employee fields, so the datasubset is structured like the employee cdt.

    Hope this helps,
    Alex
  • It would probably be much more efficient to go the route of creating a view. Most DBMS implementations are much faster at joining data sets than Appian is. Do all your joins in the database to get your view. Only use Appian to query the view.