web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Filter grid-Queryrange

(0) ShareShare
ReportReport
Posted on by 515

Hi,

I have a form with grid example-InventSerial in AX 2012- It iis customized.

The invent serial has customized field as Status-values are registered, available,scrap,not avaible,machine deployed etc

The user wanted me to filter the invent serial form where he should see all the values except Status -------Registered

So I went to execute query and wrote a range --

inventserial_ds.query().dataSourceTable(tablenum(InventSerial)).addRange(fieldnum(InventSerial, Status1cust)).value(strfmt('!%1', Status1cust::registered));

My query is filtered but it shows as below(image attaced)

Since I dont want user to change the filter, i applied Statusrange=Locked & hidden. As a result the field on form is not available for fileteration(it is greyed out and cant filter)

but the user want the field to be filter to be filterable.

Is there a trick or workaround where I can filter the form with status (!=registered) but also make that field fileterableNotregsitered.PNG

Notresgister_2D00_1.PNG

There can be some workaround to achieve this

please help

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,035 Super User 2025 Season 2 on at

    Hi NDingankar22,

    You can create a view where you exclude the registered status. Then use this view as data source on the form. In that case, the filtering on the status field will be available.

  • Suggested answer
    Pedro Tornich Profile Picture
    955 on at

    Hi,

    In AX2012 after hiding or locking the range the user can no longer edit it, but there is a workaround in the query level to solve this.

    You can use a query range expression to bypass the range status behavior.

    Here is a sample code used on the CustInvoiceJournal form to hide a specific sales order, but still allowing the user to filter on the sales order field:

    range = CustInvoiceJour_ds.queryBuildDataSource().addRange(fieldNum(CustInvoiceJour, DataAreaId));
    range.value(strFmt('(%1.%2 != "000002")',
        tableStr(CustInvoiceJour),
        fieldStr(CustInvoiceJour, SalesId)));
    range.status(RangeStatus::Locked);
    

    You can find more information on query range expressions in the following link:

    http://www.axaptapedia.com/Expressions_in_query_ranges

  • NDingankar22 Profile Picture
    515 on at

    Hi,

    Thank you for the reply

    I couildnt filter with above code of dataareaid-I m writing it in execute query method before super

    May you highlight more please?

    thank you

  • Suggested answer
    Pedro Tornich Profile Picture
    955 on at

    Try placing your code at the end of the form init() method.

  • NDingankar22 Profile Picture
    515 on at

    I tried but no luck. The form is based on InventSerial datasource

    So, putting the below code in init SHOWS the registered value on form

    range = inventserial_ds.queryBuildDataSource().addRange(fieldNum(InventSerial, DataAreaId));

    range.value(strFmt('(%1.%2 != "Registered")',tableStr(InventSerial),fieldStr(InventSerial, SerialItemStatus)));

    range.status(RangeStatus::Locked);

    Am i doing anything wrong here? Please suggest

  • Verified answer
    Pedro Tornich Profile Picture
    955 on at

    Your range value is wrong.

    Since the field you are trying to add the range to is a BaseEnum you need to compare it to an integer value (without quotes), like the following:

    range.value(strFmt('(%1.%2 != %3)', tableStr(InventSerial), fieldStr(InventSerial, SerialItemStatus), enum2int(SerialItemStatus::Registered));

    There is a complete example about filtering by enum fields on the link I shared before.

  • NDingankar22 Profile Picture
    515 on at

    Hey Pedro

    thank you so much for your assistance

    yes it works..thanks again for your help

  • Pedro Tornich Profile Picture
    955 on at

    I'm glad it worked :)

    If you don't have any more questions about this, please mark the answer as verified, to help other members in the community.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 584 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 499 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans