Monday, December 28, 2009

How to prompt a user with a query window


This seems pretty straight forward but I've been asked it a few times so I'll write about it: "How can I display an interactive query window to the user in code that looks like the Advanced Query Tool?"

This can be done by taking the QueryRun value and running its method queryRun.prompt() which will return a Boolean value. If the user hits enter, the returned value will be true. If the user cancels out, the value will be false. For this reason, we would want to put this prompt in an if block:

Query query = new Query();
QueryBuildDataSource qbds;
QueryRun queryRun;
;

qbds = query.addDataSource(tableNum(CustTransOpen));
qbds.addRange(fieldNum(CustTransOpen, AccountNum));

queryRun = new QueryRun(query);

if (queryRun.prompt())
{
     // Run code
}

1 comment: