Errors in expression rule when multiple matches from the database.

Hi All,

I am getting the error if multiple matches exist for the filter criteria. Below given is the code. Can anyone please help me out?

a!queryEntity(
entity: cons!TEMS_ENTITY_V_TE_DETAILS,
query: a!query(
paginginfo: a!pagingInfo(1, - 1),
logicalexpression: a!queryLogicalExpression(
operator: "OR",
filters: {
a!queryFilter(
field: "cafNumber",
operator: "=",
value: tostring(local!selectedCaf)
)
}
)
),
fetchTotalCount: true
).data

  Discussion posts and replies are publicly visible

  • Please share your current version of the top 4 lines of code.  Here's what I think you would need to have currently for it to work (and not give the error message even when the query results in an empty return set):

    a!localVariables(
      local!asset: rule!BC_QE_GetVAsset(
        partid: ri!asset.partId,
        isHazardous: 1
      ).data,
      
      a!formLayout(
        label: "Summary of Asset" & " " & property(local!asset, "partId", "[no matches found]"),

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Hi Mike, 

    Your coding worked. But facing another issue now. I am getting an error for the quantity field now. So I should be using property function for all the remaining fields? 

    alVariables(
      local!asset:rule!BC_QE_GetVAsset(partid: ri!asset.partId,isHazardous: 1).data,
      a!formLayout(
        contents: {
          a!richTextDisplayField(
            value: {
              a!richTextItem(
                text: (
                  "Summary of" & " " & "Asset" & " " & property(local!asset, "partId", null),
                ),
                color: "ACCENT",
                size: "MEDIUM_PLUS",
                style: "STRONG"
              )
            }
          ),
          a!boxLayout(
            label: "This asset is no longer available",
            showWhen: local!asset.quantity = 0,
            style: "#cc0000",
            marginBelow: "STANDARD"
          ),

    Thanks

  • Yes, if there's any chance in the query returning an empty value, in such a way that "local!asset" would come back null rather than containing a valid dictionary, then you'd need to access its properties using property() to avoid the error.  But you should consider whether this is really a valid use case first - or whether you should be gatekeeping this at a higher level (in other words, only letting users access this interface when you already know the query will return a valid dictionary into local!asset).  If you can be sure of that, then you can access the properties directly using dot property notation.

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Thank you Mike for your input.