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

  • 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

    Hi, can try type casting the data type to the required CDT type. 

  • It sounds like your returned data set is empty based on that error message.  First I would suggest updating the a!textField()'s value parameter to is the property() function as:

    property(local!data,"permittedTeRange",null)

  • 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.