Execute Permanent Query Based On Its Name
/*
* Execute Permanent Query Based On Its Name
*
* @author David Pech <dpech@chemaxon.com>
*/
evaluate = { widget ->
    def rs = widget.form.resultSet
    def dataTree = rs.dataTree
    // get the queries
    def queries = dataTree.getQueries()
    def DFQueries = queries.getItems()
    // set the name of the permanent query you want to execute
    // also unique part of the name will work
    def queryName = "YourQueryName"
    // loop through all of the permanent queries
    for (i = 0; i < DFQueries.size(); i++) {
        def DFQuery = DFQueries.get(i)
        // if the name matches the query name, execute the query
        def name = DFQuery.getHandle().getInstance().getName()
        if (name.toLowerCase().contains(queryName.toLowerCase())) {
            def expression = DFQuery.getExpression()
            println "Executed query name: " + name
            def rsLock = rs.lockable.withLock('querying') { rsEnv ->
                rs.applyQuery(expression, rsEnv)
            }
        }
    }
}