Is it possible to replace the LABKEY.Filter.Types.IN filter on a query with a parametrized query instead?

LabKey Support Forum (Inactive)
Is it possible to replace the LABKEY.Filter.Types.IN filter on a query with a parametrized query instead? Leo Dashevskiy  2015-10-20 15:06
Status: Closed
 
Or is it not possible because this LABKEY.Filter.Types.IN filter's value is not primitive, but more like an encoded array of strings?

Thanks.
-Leo
 
 
Jon (LabKey DevOps) responded:  2015-10-21 12:13
Hi Leo,

Can you give us some more details as to what you're looking to do here?

The LABKEY.Filter.Types.IN is the equivalent of an OR operator in SQL, using semi-colons to separate the values you're looking to find within the specific column you're running the filter against. Are you trying to use the LABKEY.Filter.Types.IN filter as a parameterized query like this?

<script type="text/javascript">

var myFilter = LABKEY.Filter.create('Language', 'English;German;Spanish', LABKEY.Filter.Types.IN);

LABKEY.Query.selectRows({
    schemaName: 'lists',
    queryName: 'People',
    success: onSuccess,
    filterArray: [ myFilter ]
    });

function onSuccess(data)
{
    alert("Success! " + data.rowCount + " rows returned.");
}

</script>

Regards,

Jon
 
Leo Dashevskiy responded:  2015-10-21 12:20
Title: Is it possible to replace the LABKEY.Filter.Types.IN filter on a query with a parameterized query instead?
Hi Jon,

Actually, I would like to replace one with the other in the instantiation of a QueryWebPart:

Instead of this:

                    qwpResponse = new LABKEY.QueryWebPart({
                        filters: [
                            LABKEY.Filter.create(
                                'arm_accession/name',
                                cohorts,
                                LABKEY.Filter.Types.IN
                            )
                        ],
                        queryName: response,
                        schemaName: 'study'
                    })

where cohorts is of type "a;b;c"

I'd like to have this:

                    qwpResponse = new LABKEY.QueryWebPart({
                        parameters: <blah>,
                        queryName: responseParameterized,
                        schemaName: 'study'
                    })

Is that possible?

Thanks.
-Leo
 
Jon (LabKey DevOps) responded:  2015-10-21 13:00
Hi Leo,

I think I understand what is going on.

If you have a query that is parameterized and requires values, then yes you can have parameters for your QWP as well if you need it to pass parameters to it automatically rather than requiring the user to input them in.

So your second example would be correct:

                    qwpResponse = new LABKEY.QueryWebPart({
                        parameters: <blah>,
                        queryName: responseParameterized,
                        schemaName: 'study'
                    });

So <blah> would have to be coded as:

{'fieldname': 'value', 'fieldname2': 'value'}


Please refer to our docs here for more information and an example API call that uses the QWP:

https://www.labkey.org/wiki/home/Documentation/page.view?name=paramsql

Regards,

Jon
 
Leo Dashevskiy responded:  2015-10-21 14:44
I've already read the docs that you pointed to in your link, but still I don't understand, how exactly what I'm after can be achieved?

I mean, I can add the "parameters" config to my QueryWebPart instantiation:

qwpResponse = new LABKEY.QueryWebPart({
 ...
 parameters: { 'arm_accession/name': cohorts },
 queryName: responseParameterized,
 ...
});

where cohorts == 'a;b;c'


But how exactly should my SQL query be changed to capture the behavior of the "LABKEY.Filter.Types.IN" filter?!
 
Jon (LabKey DevOps) responded:  2015-10-21 15:25
Hi Leo,

Thanks for clarifying. What you're asking isn't possible here through the parameters config. You can only provide your parameter one value and cannot have it run as if it were an OR statement this way.

If you need to have multiple values appearing, then you would have to use the LABKEY.Filter.Types.IN as a filter rather than a parameter and you would have to forgo using that specific parameter within your original SQL query. This is the only way you can tell the system to give you multiple cohorts rather than just one at a time.

Does that make sense?

Regards,

Jon
 
Leo Dashevskiy responded:  2015-10-21 15:36
Yes, thanks Jon, so the answer to the starting question is NO, as I suspected, because "value is not primitive, but more like an encoded array".

It is also not possible, instead of the current approach of providing a string with a query name, where that query is defined statically elsewhere, to have a string that has SQL code provide results for the creation of the QueryWebPart, is it?
 
Jon (LabKey DevOps) responded:  2015-10-21 17:21
Hi Leo,

I'm not certain I'm understanding your follow-up question.

The QWP does have a config.sql you can use in lieu of an existing schema name/query name combination, but I'm not sure where you're going with the "query is defined statically elsewhere" part.

Are you trying to generate a QWP based on a table/query that is already parameterized and you're trying to use inject in different SQL to display in your QWP instead to accomplish your parameterization needs having multiple Cohorts?

Regards,

Jon
 
Leo Dashevskiy responded:  2015-10-21 17:25
Jon, you're absolutely right. I was indeed thinking about the 'sql' config and somehow overlooked it.

I think I can accomplish what I'm after: phasing out the IN filter type with generating the needed SQL in place and swapping it out as needed.

Thanks for you help.
-Leo