Condividi tramite


Customizing the Query Form

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

The Query form is displayed prior to a query being run and enables users to change the elements of a query. Use the Query form to do the following:

  • Modify data sources.

  • Specify ranges.

  • Define a sort order.

  • Save the query.

By default, the Query form is the SysQueryRun form that's specified by a query's Form property. To implement your own Query form, create a form, and then set the Query.Form property to the name of the custom form.

Display the Query Form from the Application Object Tree

  1. Navigate to the Queries node.

  2. Right-click the query, and then select Open.

The Query form uses the SysQueryRun application class, which extends the QueryRun kernel class.

Display the Query Form from Code

Display the Query form from code by using the QueryRun.prompt method. The following example instantiates the SalesQuotationUpdate query, displays the Query form by calling the prompt method, and then iterates through the returned records.

    static void RunSalesQuotationUpdate(Args _args)
    {
    
    QueryRun    SalesQuotationUpdate;
    SalesQuotationTable SalesQuotationTable;
    
    ;
    
    SalesQuotationUpdate = new QueryRun(QueryStr(SalesQuotationUpdate));
    
        if (SalesQuotationUpdate.prompt())
        {
            while (SalesQuotationUpdate.next())
            {
                if (SalesQuotationUpdate.changed(tablenum(SalesQuotationTable)))
                {
                    SalesQuotationTable = SalesQuotationUpdate.get(
                        tablenum(SalesQuotationTable));
                    info(SalesQuotationTable.QuotationId);
                }
            }
        }
    }

Customize the Query Form

Customize the Query form by calling methods that are available from the SysQueryRun class. The following table describes the options that can be set for the Query form.

Option

When the value is set to

Default

Allows the user to add a child data source.

SysQueryRun.promptAllowAddDataSource

    (true);

true

Allows the user to add a range.

SysQueryRun.promptAllowAddRange

    (QueryAllowAdd::AllFields);

QueryAllowAdd::

AllFields

Allows the user to add a sort order.

SysQueryRun.promptAllowAddSorting

    (QueryAllowAdd::AllFields);

QueryAllowAdd::

AllFields

Allows the user to save or delete the query.

SysQueryRun.promptAllowSave(true);

true

Displays and loads the Query form with the query that was last run, its data sources, ranges, and sort orders.

SysQueryRun.promptLoadLastUsedQuery

    (true);

true

Allows queries to be saved for each user. Users can also delete their own saved queries.

SysQueryRun.promptSaveQueryPrUser

    (true);

true

Allows users to change and save their queries. If false, the user cannot change or save a query.

Query.userUpdate(true);

true

Displays the Query form's Select query combo box.

SysQueryRun.promptShowQuerySelect

    (true);

true

Displays the Reset button, which sets all the data sources, ranges, and sort orders to their original states.

SysQueryRun.ShowReset(true);

true

Displays the Sorting tab.

SysQueryRun.promptShowSorting

    (true);

true

See also

Query Elements in the AOT

Accessing Data

How to: Create Queries by Using X++

How to: Create Queries by using the AOT

Query Object Model

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.