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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Filtering Form by View Field AX2012

(0) ShareShare
ReportReport
Posted on by 282

Hi all, running AX2012 R3 CU8.

Follow-up to: https://community.dynamics.com/ax/f/33/t/170411

After filtering by a table field using the following instructions, http://dynamics-ax-live.blogspot.co.uk/2010/03/how-to-filter-records-in-form-by-code.html I was able to get the desired result. However, in a later example I tried to do the same thing with a View field and it didn’t work

 

Is the code instruction different for this? It specifically falls over when adding the range.

(the example used: CurrencyQBR = this.query().dataSourceName('CustTable').addRange(fieldnum(CustTable,Currency));)

 

I suspect “fieldNum” needs to be something else.

Thanks in advance for any help :)

*This post is locked for comments

I have the same question (0)
  • jasman Profile Picture
    1,413 on at
    RE: Filtering Form by View Field AX2012

    What is the view you are trying to apply the range on ?

  • 5400 Profile Picture
    7,162 on at
    RE: Filtering Form by View Field AX2012

    what is your view.. are you adding view in data source. can send some screen shot with requirement.

  • Martin Dráb Profile Picture
    236,955 Most Valuable Professional on at
    RE: Filtering Form by View Field AX2012

    It's done in the same way, including fieldNum().

    By the way, I would rewrite the code to this.queryBuildDataSource().addRange(...); hard-coding datasource name is bad because the code stops working if anybody renames the datasource.

  • lukbel Profile Picture
    282 on at
    RE: Filtering Form by View Field AX2012

    Hi all, thanks for your interest

    It's basically a separate custom view that I created, which I linked to the SalesLine table through an inner join, and displays information related to that sales line.

    This is displayed on the form, which queries mainly the SalesLine table, plus this one field. It displays and filters alongside it in the grid and everything works fine.

    I've actually retried it and this time I'm not getting an error, however, when I open the form, the range hasn't been applied. Screenshots to follow:

  • lukbel Profile Picture
    282 on at
    RE: Filtering Form by View Field AX2012

    The data sources used in my form (linked by InnerJoin)

    6281.Capture4.PNG

    The three methods edited to attempt to add the filter:

    5125.Capture2.PNG3566.Capture3.PNG6281.Capture4.PNG

    The actual form itself (does not attempt to filter)

    6281.Capture5.PNG

    (for some reason someone decided it was a good idea to return the value as a string not an integer, this is why I phrase queryvalue as '0' and not just 0)

  • lukbel Profile Picture
    282 on at
    RE: Filtering Form by View Field AX2012

    Hi, thanks Martin that's sound advice, I'll do that now - can you see an error in the screenshots provided that would be causing it not to filter?

  • Martin Dráb Profile Picture
    236,955 Most Valuable Professional on at
    RE: Filtering Form by View Field AX2012

    Look at the query used when you get wrong result to understand what's wrong. One option is the Query tab in Personalization form. Another is calling toString() on the root QueryBuildDataSource.

    Debugging queries without looking at them is difficult - and unnecessary.

  • lukbel Profile Picture
    282 on at
    RE: Filtering Form by View Field AX2012

    Of course, I forgot that the changes would actually show up regardless

    In the Query Used window under Ctrl+F3 the filter range shows up, but the criteria is blank. This happens regardless of what is entered in queryvalue, I tested it with various strings and formats. Have I put my value in the wrong place?

  • 5400 Profile Picture
    7,162 on at
    RE: Filtering Form by View Field AX2012

    If your range is static why not creating query and add the range in query level after that you can add query into view.

    so you have inner relation already in data source level, please create the relation in saleline  and check.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Filtering Form by View Field AX2012

    Does the Debugger stop where you add the value to the range? Mind you, if you connect the datasources with inner join it only goes through executeQuery() of the main data source.

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans