Change the Named Query Path

Is it possible to change the Named Query being run based on a value chosen in a dropdown list?

I have a dropdown list that is responsible for returning users from a named query with results like this:
Where the number is the selected value and the name is what the user sees in the dropdown.
ID ----Name

I am wondering if it is possible to dynamically change a named query that is being run on a table based on the user choice from the dropdown. So if a user selected (-2) ALL it would run a named query that would use one type of named query and if a user chose any of the other options a different named query would be run on the Named Query binding on the table.
So far I have not been able to find a way to change the named query being run, I am thinking that if it is possible it would only be using scripting or through an expression.

I think your best bet is to do this in a property change script on the dropdown as I don’t think you can dynamically change the named query used in a Named Query expression (not to mention not sure how you’d bind the changing parameters).

Something like this would work though

if event.propertyName == 'selectedValue':
    if event.newValue == -2:
        params = {'someParam':1}
        namedQuery = 'path/to/namedQuery1'
   elif event.newValue == -1:
       params = {'otherParam':2}
       namedQuery = 'another/named/query'
   # continue for other cases and then
   ds = system.db.runNamedQuery(namedQuery, params) = ds

This also means the data binding on the table should be blank.

The only issue you may run into is that by having one table handle multiple named queries and what not, you may need to also customize the column attributes in each case as well, to tell the table to hide this column, format this column a certain way, etc each time. Or perhaps this could go inside one of the tables extension functions.

1 Like