IN operator not working

-------Updated below code--------------

Hi ,

local!data: a!queryEntity(
entity: cons!TEST ,
query: a!query( )
),

local!dataF:index(local!data.data,wherecontains((9555),year(local!data.data.date))),



local!dataH: a!queryEntity(
entity: cons!HELLO,
query: a!query(
logicalExpression: a!queryLogicalExpression(
operator: "AND",
filters: {
if(rule!APN_isBlank(local!dataF.name),
{},
a!queryFilter(
field: "name",
operator: "in",
value: local!dataF.name
)
)})))

By running above code i am getting below error.

Expression evaluation error at function a!queryEntity [line 80]: Cannot apply operator [IN] to field [componentId] when comparing to value [TypedValue[it=3,v=1027A]].

Why IN operator i not working inside query filter. Outside its printing correct value. What exactly its expecting ?

Can any help me on this ?

  Discussion posts and replies are publicly visible

  • Hello Saurav

    The type 3, if I am not wrong is the text. (Check it using this typename(3) )

    So I am guessing the id on which you have the “in” is an integer. So if you try to pass a text on a field which is an integer makes sense getting that error.

    Why this is happening? Well the joinarray resturna a text. The problem is around that.

    I was trying to follow your code and seems like you took out some pieces there.

    Hope this helps

    Jose

  • typo error. Please consider id as text here

    local!data: a!queryEntity(
    entity: cons!TEST ,
    query: a!query( )
    ),

    local!dataF:index(local!data.data,wherecontains((9555),year(local!data.data.date))),

    local!dataH: a!queryEntity(
    entity: cons!HELLO,
    query: a!query(
    logicalExpression: a!queryLogicalExpression(
    operator: "AND",
    filters: {
    if(rule!APN_isBlank(local!dataF.componentId),
    {},
    a!queryFilter(
    field: "componentId",
    operator: "in",
    value:local!dataF.componentId
    )
    )})))

    Its comparing text to text only.

  • 0
    Certified Senior Developer
    in reply to sauravk

    Jose is correct, 

    seems Id is integer not TEXT,

    Try this

    a!queryFilter(
    field: "componentId",
    operator: "in",
    value:tointeger(local!dataF.componentId)
    )

  • we can not convert text to integer.

    Id's are like "1026A"

    that need to match

  • 0
    Certified Lead Developer

    You are trying to find whether or not a specific string, such as your example "1026A", is located within a list of strings, local!test.  There's one fundamental problem with this.  You used the joinarray function on local!test.  It is no longer many strings from which you can find "1026A"; it's one long, massive string containing all the search results concatenated together with commas.  It's not a list, but a single entity, which "IN" fails to recognize because it's expecting a list.

    Don't use the joinarray function here.  Instead, try a!flatten, which should remove all nesting and leave you with a nice, clean list of strings.

    Try commenting out the query and having the whole rule just return local!test instead until it's squared away, then uncomment and try polishing the query again.  It's possible that the first query isn't returning the same type as the second one, or that neither one are returning the type you expect.

  • If both id and componentid are from the same nature, try this

    a!queryFilter(

    field: "id",

    operator: "in",

    value:local!datasubsetF.componentId

    )

  • with(
    local!dataOne: a!queryEntity(
    entity: cons!TEST,
    query: a!query(
    a!paginInfo(
    1,
    - 1
    )
    )
    ).data,
    local!dataTwo: index(
    local!dataOne,
    wherecontains(
    tointeger(
    9555
    ),
    tointeger(
    year(
    index(
    local!dataOne,
    date
    )
    )
    )
    ),
    {}
    ),
    local!test: joinarray(
    index(
    local!dataTwo,
    "componentId",
    ""
    ),
    ","
    ),
    local!dataFinal: if(
    rule!APN_isEmpty(
    local!dataTwo
    ),
    null,
    a!queryEntity(
    entity: cons!HELLO,
    query: a!query(
    logicalExpression: a!queryLogicalExpression(
    operator: "AND",
    filters: {
    if(
    rule!APN_isBlank(
    local!dataTwo.id
    ),
    {},
    a!queryFilter(
    field: "id",
    operator: "in",
    value: {
    tointeger(
    local!test
    )
    }
    )
    )
    }
    )
    )
    )
    )
    )

  • That only trying but giving same issue.
    Expression evaluation error at function a!queryEntity [line 78]: Cannot apply operator [IN] to field [componentId] when comparing to value [TypedValue[it=,v={TypedValue[it=,v=],TypedValue[it=,v=],TypedValue[it=3,v=]}]].

  • The error seems to say that you have something empty on the output, maybe a reject (isnull(_), local!datasubsetF.componnentId ) Can help

    Or something similar

    Can you please provide the whole snippet, I don’t see where the variable is created datasubsetF

  • This is very straight issue. I am passing one view output in another view query filter. In view a we have fields data type is string which we are passing to another view and trying to filter that. But getting above error which is very weird .

    But in your response you are converting to toInteger() but we have field string type not integer type like "1027A"