Show specific reports in a read-only grid

I have two record types:

1. Asset

2. Match Report

The Assets have a one-to-many relation with the Match Report

I want to show an Asset specific grid where it shows all the Match Reports of that Asset

I have created a read-only-grid where I query that the assetId should match the match_report.asset.assetId

This only works if the Asset has a minimum of one Match Report created

If there are no match reports available linked to the asset, the query will fetch all match reports from all assets and show them in the grid.

Can someone help me to make sure the grid is empty if there are no match reports available? 

This is my query in expression: 

a!queryLogicalExpression(
  operator: "AND",
  filters: {
    a!queryFilter(
      field: "asset.assetId",
      operator: "=",
      value: ri!AM_Match_Report.asset.assetId
    )
  },
  ignoreFiltersWithEmptyValues: true
)

  Discussion posts and replies are publicly visible

Parents
  • You probably need to put an if() statement around the entire query. What you want to happen is that you should only query IF there is an asset ID to filter on. Otherwise, you should just return nothing. So, you could set up a query like this to define the data for your grid:

    if(
      isnull(ri!AM_Match_Report.asset.assetId),
      null,
      a!queryEntity(
        entity: cons!YOUR_CONSTANT_HERE,
        query: a!query(
          pagingInfo: a!pagingInfo(
            startIndex: 1,
            batchSize: 10
          ),
          logicalExpression: a!queryLogicalExpression(
            operator: "AND",
            filters: {
              a!queryFilter(
                field: "asset.assetId",
                operator: "=",
                value: ri!AM_Match_Report.asset.assetId
              )
            },
            ignoreFiltersWithEmptyValues: true
          )
        )
      )
    )

    I'm not sure how you are actually using this in your grid, so it's possible the null on line 3 is not correct in your scenario - however, you can replace that with other things (e.g. todatasubset({}) if you want it to return a blank datasubset for your grid).

  • Hi Peter, thanks for your answer. Also not working unfortunately. Since the assetId is never NULL. I can not imagine this should be very difficult to achieve.. This should be basic functionality right? Am I just overcomplicating it?

  • 0
    Appian Employee
    in reply to Ozin

    Yeah something isn't quite adding up. Did you try running the query separate (like directly in an expression rule) and trying different inputs to make sure it works? I'm also confused about the value in the filter expression you gave above. This looks like it's coming from a rule input for Match_Report. However, shouldn't this come from an Asset rule input if you're display the corresponding match reports for the given asset?

  • 0
    Certified Lead Developer
    in reply to Ozin

    Hi Ozin,

    Peter's suggestion should have worked. To better understand your use case, can you share the entire code of your interface and QE expression?

  • Hi, 

    This is the interface expression:

    {
      a!gridField(
        label: "Read-only Grid",
        labelPosition: "ABOVE",
        data: a!queryEntity(
          entity: cons!AM_POINTER_TO_MATCH_REPORT_ENTITY,
          query: a!query(
            selection: a!querySelection(
              columns: {
                a!queryColumn(
                  field: "matchReportId"
                ),
                a!queryColumn(
                  field: "match"
                ),
                a!queryColumn(
                  field: "date"
                ),
                a!queryColumn(
                  field: "link"
                ),
                a!queryColumn(
                  field: "comment"
                ),
                a!queryColumn(
                  field: "matchDetails"
                )
              }
            ),
            logicalExpression: a!queryLogicalExpression(
              operator: "AND",
              filters: {
                a!queryFilter(
                  field: "asset.assetId",
                  operator: "=",
                  value: ri!AM_Match_Report.asset.assetId
                )
              },
              ignoreFiltersWithEmptyValues: true
            ),
            pagingInfo: fv!pagingInfo
          ),
          fetchTotalCount: true
        ),
        columns: {
          a!gridColumn(
            label: "Match Report Id",
            sortField: "matchReportId",
            value: fv!row.matchReportId,
            align: "END"
          ),
          a!gridColumn(
            label: "Match",
            sortField: "match",
            value: fv!row.match
          ),
          a!gridColumn(
            label: "Date",
            sortField: "date",
            value: fv!row.date,
            align: "END"
          ),
          a!gridColumn(
            label: "Link",
            sortField: "link",
            value: fv!row.link,
            align: "END"
          ),
          a!gridColumn(
            label: "Comment",
            sortField: "comment",
            value: fv!row.comment
          ),
          a!gridColumn(
            label: "Match Details",
            sortField: "matchDetails",
            value: fv!row.matchDetails
          )
        },
        validations: {}
      )
    }

    This is the interface rule in the record type:

    rule!AM_AssetPerformance(
      rule!AM_GetReportById(
        rf!assetId
      )
    )

    This is the AM_GetReportById code:

    a!queryEntity(
      entity: cons!AM_POINTER_TO_MATCH_REPORT_ENTITY,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "asset.assetId",
              operator: "=",
              value: ri!id
            )
          },
          ignoreFiltersWithEmptyValues: true
        ),
        pagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: 50
        )
      ),
      fetchTotalCount: false
    )
    .data

  • It looks like your interface input and grid field are querying the same data source.  Is that true?  Could you just pass "assetId" into the interface rule with the grid field?

  • It doesn't work. Little bit lost here. How do you usually do this? I just want to show the match reports of only that player in a site on a seperate view. 

  • Change the input to the interface to an integer "assetId" and update the queryFilter to:  a!queryFilter(
    field: "asset.assetId",
    operator: "=",
    value: ri!assetId
    )...otherwise it looks like you are querying the data twice.  This may not address your issue of the query returning a null.  

Reply Children
No Data