Old-Timer TRICK: GETTING THE SQL FROM THOSE MorphX Queries

Old-Timer TRICK: GETTING THE SQL FROM THOSE MorphX Queries

The

There are some tricks that have been around forever but are just as good today as they were back in the old days. In this post, we will learn two little tricks that I nearly use on every single assignment, and I’ve used them for a long time.

Let’s just say that you need the SQL or X++ from a query. Traditionally, you hover your mouse over the first datasource listed but end up with this disappointing tease because the underlying code gets cut-off and you can’t see it all.

Case in point:

So, two ways to handle this. How you handle it depends on whether you are using a form or a query. For a query, simply creating a job and writing code like this works:

static
void getSQL(Args _args)

{

Query query;

query = new Query(queryStr(AxdVendInvoice));

info(query.dataSourceNo(1).toString());

}

Or here is a screenshot:

This is particularly easy because the only thing that you need to know is to put the name of the query in the querystr part.

Now, a form is slightly different..

Once again, you only need to change one word… This time, put the name of your form in the formstr part.

static
void GetStringFormQuery(Args _args)

{ Query formQuery;

FormDataSource formDataSource = new FormDataSource();

FormRun formRun;

Args args = new Args();

args.name(formStr(VendInvoiceInfoListPage));

formRun = classFactory.FormRunClass(args);

formRun.init();

formDataSource = formRun.objectSet();

formQuery = formDataSource.query();

info(formQuery.dataSourceNo(1).toString());

}

And here is the screenshot:

And let’s run one of the jobs that we wrote and see the output:

We can highlight this and copy and paste it into notepad to get the full goodies. Nice quick and easy way to get what you need.

Videos