Create this Query in Wappler

What we seem to need is an effective way of converting a data query into an array in suitable format to use with IN/ NOT IN

I think we have that. Patrick has provided an alternative to the non-working values function. Unless I misunderstood the original question, I think this is the simplest solution.

Actually, initial tests seem to indicate that all is needed is to add

{{ queryname.groupBy(‘id’).keys() }}

Into the query designer, no json hacks needed

1 Like

Server action

image

Result (as seen by table generator)

where query2 is defined as above

1 Like

Getting an errror: Can not convert Array to String.
I set the value of {{queryname.groupBy(‘id’).keys()}} to a variable using SET VALUE to check, and this is the value returned:
{"aa" : ["11","13","43"]}

These IDs are correct, but NOT IN condition still doesn’t work and throws the above error.

See also:

6 Likes

I imagine you’re using the curly single quotes just to display here (if you were actually using them, that would cause an error).

I’m sure your expression is correct. I was getting the same error when using the values function. It might be worth checking the code to make sure it has updated correctly. I’ve done a number of experiments with this now , and haven’t had any problems using expressions like this.

Yeah the quotes were an issue the first time I tried. But I fixed that to {{queryname.groupBy('id').keys()}} and I am getting a response in the variable as shared above.
But the query gives the conversion error.

Are you sure you are getting multiple IDs from your test exclusion query?

Yes - definitely getting the results I expect.

Here are the steps:

image

Turning on output only for the Set Value line, this is the raw data returned by running the query:

{"excl_ids":[5670,5631,5613,5431,5155,5047,4919,4910,4734,3997,5812,5814]}

image
Response for me is still:
{"aa":["30","16","11"]}

code_value_id is numeric in DB. Don’t know why its coming as string. I see output for you is numbers.
Are you using .NET or PHP? I am using .NET with MySQL 8.0 odbc driver.

I’m using PHP.

Must be IIS related then.
@patrick can you please check this?

It’s strange that the results are being returned as text. Is that definitely an issue with the array conversion or is that how the results are returned by the first query? Also, I think the query should work even if the numbers are in quotes, so perhaps there is another issue.

Amazing @George

Exactly what i asked for many months ago

1 Like

NishKarsh, did you try NOT editing the file and just adding the {{queryname.groupBy(‘id’).keys()} into the query editor conditions as above, worked perfectly for me

I deleted the edited server action. Made this from scratch and added the groupby in condition and set value.

Yeah… quotes is probably not the issue.

Shot in the dark, try {{query1.groupBy(“id”).keys().toNumber()}}?

Error: Can not convert Array to Double. :sweat_smile:

which stage is generating the error, i am not having the same issues as you,

query1 (get exceptions)
query2 get results condition NOT IN {{query1.groupBy(“id”).keys()}} and {{query1.groupBy(“id”).keys().toNumber()}} both work via the visual builder for me?

The condition in query is generating error.
The group by itself is working, but when used in condition parameter for NOT IN, it says Cannot convert array to string.
I am able to print the value of group by using set value, so I know that part is working.

Are you testing this on IIS with MySQL too?