How to identify advanced query or dynamic joins from query window?

268 views Asked by At

In the query window that pops up, if a user right clicks and chooses "1:n" and selects a table, how can one detect and use that table? I have a good sample job and screenshots that should demonstrate what I'm trying to accomplish.

I wrote this sample job that dumps out the AOT query objects but not the dynamically joined table/range/value.

static void InventSumQuery(Args _args)
{
    Query               query = new Query(queryStr(InventDimPhys));
    QueryRun            qr = new QueryRun(query);
    QueryBuildRange     queryRange;

    DictField           dictField;

    int i, n;


    if(qr.prompt())
    {
        for (n=1; n<=query.dataSourceCount(); n++)
        {            
            for (i=1; i<=query.dataSourceNo(n).rangeCount(); i++)
            {
                queryRange = query.dataSourceNo(n).range(i);

                dictField = new dictField(query.dataSourceNo(n).table(), fieldName2id(query.dataSourceNo(n).table(), queryRange.AOTname()));

                info(strFmt("%1.%2", tableId2name(dictField.tableid()), dictField.name()));
            }
        }
    }

    info("Done");
}

Screen1

Screen2

Screen3

1

There are 1 answers

0
Alex Kwitny On BEST ANSWER

Of course I figure my own answer out. Query objects are static, and the query form actually just modifies the query when you make the change.

So you need to modify the code above to:

if(qr.prompt())
{
    query = qr.query();

This gets the modified query. The advanced querying actually is just a function of the form itself that ultimately modifies the query.