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

Parents
  • 0
    Certified Senior Developer

    Hi shubhamy,

    1.) please try this function for inserting code.

    This makes the life of your content reader way easier.

    2.) What is the error telling you, can you insert as well?
    what is the overall use case? Often its not an issue of your query and more of the usage of the query.

    3.) 

    a!queryLogicalExpression(
    operator: "OR",
    filters: {
    a!queryFilter(
    field: "cafNumber",
    operator: "=",
    value: tostring(local!selectedCaf)
    )
    }
    )

    a) why are you using "OR"?

    b) why are you using querylogialexpression and not just the "filter" parameter of your query if you are looking for just one value in your DB?

    c.) is "local!selectedCaf" multiple?

  • Hi Richard,

    I am getting the following error:

    Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!textField [line 1606]: Invalid index: Cannot index property 'permittedTeRange' of type String into type List of Variant.

    Yes, local!selectedCaf can be multiple in dropdown but user will select only one.

  • 0
    Certified Senior Developer
    in reply to shubhamy0001

    this is a typical message if the your variable is NULL but not really Null-save
    try to use index( local!selectedCaf,"permittedTeRange",null) instead of local!selectedCaf.permittedTeRange.

    second idea: are the selecatable choicevalues all of the same type or do you have strings and numbers.... mixed up?

  • 0
    Certified Senior Developer
    in reply to Richard Michaelis

    Hi, 

    I have a similar problem while working on an interface. The interface works fine without using any local variables but I want to learn using local variables in applications. 

    I want to display a summary view of assets. When I use local variable, I am getting the following error: 

    Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!formLayout [line 4]: Invalid index: Cannot index property 'partId' of type Text into type DataSubset.

    a!localVariables(
      local!asset:rule!BC_QE_GetVAsset(partid: ri!asset.partId,isHazardous: 1),
    a!formLayout(
      label: "Summary of" & " " & "Asset" & " " & local!asset.partId
      
     
    Query Rule
    
    a!queryEntity(
      entity: cons!BC_DSE_V_ASSET,
      query: 
      a!query(
        logicalexpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "partId",
              operator: "=",
              value: ri!partId
            ),
            a!queryFilter(
              field: "isHazardous",
              operator: "=",
              value: ri!isHazardous
            )
          },
          ignorefilterswithemptyvalues: true
        ),
        paginginfo: a!pagingInfo(
          startIndex: 1,
          batchSize: 50
        ),
      )
    )  

    I tried fixing by using the index function. But not retrieving the value in the form.

    label: "Summary of" & " " & "Asset" & " " & index(local!asset,"partId",null),

    It should display as below: 

    This worked bcos I used ri!asset.partId. 

    Please advice how to fix the problem?

    And, if this works for Part Id , then Should I use index or property function for all other fields in the interface? or I can fix this in my query rule?

    TIA.

  • 0
    Certified Senior Developer
    in reply to Sandhya

    Hi Sandhya, Use below modified local variable and then it should work.

    local!asset:index(rule!BC_QE_GetVAsset(partid: ri!asset.partId,isHazardous: 1),"data",{})

  • 0
    Certified Lead Developer
    in reply to GopalK
    local!asset:index(rule!BC_QE_GetVAsset

    Assuming the rule runs a Query Entity operation, it's almost always safe to just write ".data" at the end of the rule call in cases like this since even if the rule returns empty, it'll still contain a .data property (also empty).

    local!asset: rule!BC_QE_GetVAsset(
      partid: ri!asset.partId,
      isHazardous: 1
    ).data,

    (also for getting dot properties, I still think it's cleaner code and easier to understand later, if we use "property()" to get a property, and reserve "index()" for getting an index.  but of course i know 75% of the people here have already decided they don't care about this Disappointed relieved)

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    HI Mike and Gopal,

    I tried both the methods but still showing the same error. 

  • 0
    Certified Senior Developer
    in reply to Sandhya

    Hi Sandhya , make sure your query output is not null. It should have valid data.

  • 0
    Certified Lead Developer
    in reply to Sandhya

    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

  • 0
    Certified Lead Developer
    in reply to Sandhya

    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. 

Reply Children
No Data