Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Enabling grid filters via x++ when not shown

Posted on by 620

Hi everyone,

In AX you have grid filters.

You can enable these by either pressing CTRL+G on the keyboard or by going to AX's options and enabling them for each grid.

Now what I am trying to achieve is, when the user opens the form and they are not displayed, that the code enables them.

Also when they press CTRL+G and they are gone, that AX doesn't show the form next time with the grid filters disabled.

I saw something like calling this.task(2855) in the run of your form, but it doesn't seem to work for me, or I am doing something wrong.

The example I tried came from here:

axbloggerblog.blogspot.be/.../enable-grid-filter-for-form.html

Kind regards,

Vincent

*This post is locked for comments

  • Verified answer
    Smartus Profile Picture
    Smartus 620 on at
    RE: Enabling grid filters via x++ when not shown

    Hi guys,

    First of all, thank you for helping.

    I came up with this solution:

    static void VincentGridFilterJob(Args _args)
    {
        // EDTs
        container   sysLastValueContainer, innerContainer, gridPropertiesContainer;
        str         formName, gridNameToFind, innerConValue;
        int         lastValueFromContainer;
        NoYes       areGridFiltersEnabled = false;
        
        // The usage data contains the name of the element as a first item (in terms of forms at least).
        // Search for the element name that corresponds with the name of your grid.
        // The last item of that container is a boolean which shows whether grid filters are enabled.
        container searchGridProperties(container _container, str _nameToFind)
        {
            container foundContainer = conNull();
            int idx = 0;
            int len = conLen(_container);
            
            while(idx < len)
            {
                idx++;
                
                if(typeOf(conPeek(_container, idx)) == Types::Container)
                {
                    innerContainer = conPeek(_container, idx);
                    if(conLen(innerContainer) != 0)
                    {
                        foundContainer = searchGridProperties(innerContainer, _nameToFind);
                        if(foundContainer != conNull())
                        {
                            return foundContainer;
                        }
                    }
                }
                else if(typeOf(conPeek(_container, idx)) == Types::String)
                {
                    innerConValue = conPeek(_container, idx);
                    if(innerConValue == _nameToFind)
                    {
                        return _container;
                    }
                }
            }
            
            return conNull();
        }
        
        // Init needed variables
        formName = 'VVTestForm';
        gridNameToFind = 'TestNameGrid';
        
        sysLastValueContainer = xSysLastValue::getValue(curext(), curUserId(), UtilElementType::Usersetup, formName);
        gridPropertiesContainer = searchGridProperties(sysLastValueContainer, gridNameToFind);
        
        if(gridPropertiesContainer != conNull())
        {
            lastValueFromContainer = conLen(gridPropertiesContainer);
            areGridFiltersEnabled = conPeek(gridPropertiesContainer, lastValueFromContainer);
        }
        
        info(enum2str(areGridFiltersEnabled) + ' = grid filters visible');
    }

    I used a recursive method that traverses the usage data container.

    In this container I saw that the first item is the name of the element and once I found the proper container, I needed to look at the last value which is the boolean for the grid filters.

    I have to build this in my form now, but the rest will be less hard since I now can check whether they are already enabled.

    And only if they are disabled I have to call element.task(2855).

    Thanks again guys.

    Kind regards,

    Vincent Verweij

  • Smartus Profile Picture
    Smartus 620 on at
    RE: Enabling grid filters via x++ when not shown

    Thanks for pointing me out in this direction André, I was already looking into it.

    Was just looking in the value container, but didn't see the difference yet that you pointed out.

    If I have a solution, I will post it over here.

  • Smartus Profile Picture
    Smartus 620 on at
    RE: Enabling grid filters via x++ when not shown

    Hi Ievgen,

    I agree with what you are saying, but I already did that and it still acts as a toggle.

    When you open a grid with grid filters inactive, then it will first call the task(2855) that opens the grid filters.

    Next the users closes the form, the canStart executes task(2855) again, which disables the grid filters.

    So far, so good.

    If a user opens a form and for whatsoever reason closes the grid filters and then closes the screen, it will act the other way around as what I said here above.

    He's also refering to "need to explore a bit how to handle the same effect by reading sysLastValue table", which I think that might be the solution, although not a simple one.

    Kinds regards,

    Vincent Verweij

  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,134 Super User 2024 Season 2 on at
    RE: Enabling grid filters via x++ when not shown

    Hi Vincent,

    The state of the grid filter is saved in the usage data (SysLastValue). You might be able to control the value for the users in the usage data (manipulate the value) or you can try to read the state before enabling it (element.task(2855).

    In the screenshot below you will see the data difference in the data container of the SysLastValue record. In this example it is the CustGroup form.

    Left: Grid filter disabled <> Right: grid filter enabled

    2016_2D00_07_2D00_26_5F00_22_2D00_24_2D00_52.png

    I haven't looked deeper in this direction, but it might challenge you to go into this direction.

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Enabling grid filters via x++ when not shown

    Hey Vincent Verweij ,

    Please refer to this blog post shanexp.blogspot.co.nz/.../form-method-taskint-taskid-is-executed.html

    It literally says that you need to call task(2855) on canClose() otherwise it won't filter form next time.

  • Smartus Profile Picture
    Smartus 620 on at
    RE: Enabling grid filters via x++ when not shown

    Hello Vilmos,

    This is almost what I want to achieve.

    The only thing is, when I open the form it enables the grid filters, next I close the form and re-open it, then the grid filters are gone. If I then close and open it up again, they are back.

    So it seems that this is toggle.

    I can look for the check of that AX option by performing this and then check the value of filterByGridOnByDefault whether it is true.

    UserInfo    userInfo;
        
    select firstOnly filterByGridOnByDefault from userInfo
        where userInfo.id == curUserId();

    If you can help me a little bit further with the element.task(2855) not toggling the filter grids, I'll be glad.

    Kind regards,

    Vincent Verweij

  • Verified answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Enabling grid filters via x++ when not shown

    Override the run() method of the form, and after the super() you could call:

    element.task(2855);

    Please note that if you have Filter by grid ticked on in the user options, this will disable the filter. I am unaware how to check the current status whether it is on or not.

  • Smartus Profile Picture
    Smartus 620 on at
    RE: Enabling grid filters via x++ when not shown

    Hi André,

    You are right that people should be aware of the grid filters and filter options in general.

    But it's more userfriendly if they don't have to enable them manually.

    Also I don't want to have the grid filter on each form so the option in AX's options are no option.

    To answer your second question, no it's just for one form that I am doing it.

    But do you know a way on how this can be achieved?

    Kind regards,

    Vincent Verweij

  • Suggested answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Enabling grid filters via x++ when not shown

    You may enable permanently here:

    File > Tools > Options > Interface options fast tab > Grid field group > Filter by grid on by default

    It is not advised due to some object allocation limitations in Windows that can cause problems with the AX client. Also others have reported performance problems: community.dynamics.com/.../171633

    I'd not advise to use that functionality widespread, especially not implementing it to show up for all users, only on a per-form basis.

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,134 Super User 2024 Season 2 on at
    RE: Enabling grid filters via x++ when not shown

    Hi Vincent,

    Why do you want to do this? To please users? It is a part of training to have them familiar with the filtering options.

    Are you customizing every form now?

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,134 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,928 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans