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 :
Finance | Project Operations, Human Resources, ...
Suggested answer

open form with filtration by code x++

(4) ShareShare
ReportReport
Posted on by 434
Hi,

i want to create a menu item that opens sales order form but with filtered values based on input from user
 
so i used sysOperationFramework (controller and service class) and i also created a query for filtration ("customer account", "custom field" and "status")
i hid the "batch processing" flag
 
now in the service class, how can i open the sales order form with the filtration provided by the user in the dialog?
Categories:
I have the same question (0)
  • Sohaib Cheema Profile Picture
    48,972 User Group Leader on at
    open form with filtration by code x++
    Could you not avoid coding at all, by telling users to select filters and save it as view. anytime they open the form, all they need to do is change the view. They can even set a view as default view.
     
    Having said that, if you must want to go for your custom solution, you are dealing with form patterns and said form is backed by Interaction classes (SalesTableListPageInteraction , SalesTableInteraction)
     
    All you would need is to set the filters in the query, by creating extension of interaction class.
  • DELDYN Profile Picture
    434 on at
    open form with filtration by code x++
    Hi,

    I want to do it by code, how to do it from service class?
  • Sohaib Cheema Profile Picture
    48,972 User Group Leader on at
    open form with filtration by code x++
    Your service class has no connection with these interaction classes (SalesTableListPageInteraction, SalesTableInteraction).
     
    Therefore, before we discuss the filter, may I ask you how you plan to call the Sales Order form from your service class? You mentioned a menu item, which kind of suggests that you plan to call the menu item from your service class, which would, in return, open the Sales Order form.
     
    The filters have nothing to do with where you open the form from (whether from your service class or any other class). Filters will be placed when the query is initialized in the interaction class.
     
  • DELDYN Profile Picture
    434 on at
    open form with filtration by code x++
    Hi Sohaib,

    I said i will add a menu item (in accounts receivable)

    When this menu item is clicked, a dialog will open where the user can put filters (custAccount, status and custom field)   [here i used sysOperationFramework]
     
    Now in the service class, i should add code to open the salesTableListPage form, where it will apply any filters added by the user.
    My question is, what code to put in the service class to open the form and how to also apply filters?
  • Sohaib Cheema Profile Picture
    48,972 User Group Leader on at
    open form with filtration by code x++
    Hi @DELDYN,
     
    From the description, it seems the instance of the Query object in your SysOperationFramework is different from the one used by SalesTableListPageInteraction.

    SalesTableListPage uses a query that is defined on its form.
     
    When users modify the query in your custom dialog form, they are not working with the query of SalesTableListPage.
     
    Therefore, you need to consider a solution such as saving your custom Query object somewhere. Then, in the interaction class, retrieve each range from your custom Query object and assign it to the standard SalesTableListPage query.
     
     
  • DELDYN Profile Picture
    434 on at
    open form with filtration by code x++
    Hi Sohaib,

    can you please show me the code?
  • Suggested answer
    DAnny3211 Profile Picture
    11,389 on at
    open form with filtration by code x++

    Hi DELDYN 364,

     

    To open the Sales Order form with filters applied based on user input from a SysOperation dialog, you can use the FormRun and Args classes in your service class. Here's a simplified approach:

     

    ✅ Steps in Your Service Class

     

     

    public void process(SalesOrderFilterContract _contract)
    {
        Args args = new Args();
        Query query = new Query(queryStr(SalesOrderQuery)); // Your custom query with filters
    
        // Apply filters from the contract
        QueryBuildDataSource qbds = query.dataSourceTable(tableNum(SalesTable));
        qbds.addRange(fieldNum(SalesTable, CustAccount)).value(queryValue(_contract.parmCustAccount()));
        qbds.addRange(fieldNum(SalesTable, YourCustomField)).value(queryValue(_contract.parmCustomField()));
        qbds.addRange(fieldNum(SalesTable, SalesStatus)).value(queryValue(_contract.parmSalesStatus()));
    
        args.name(formStr(SalesTable)); // Sales Order form
        args.query(query);
    
        FormRun formRun = classFactory.formRunClass(args);
        formRun.init();
        formRun.run();
        formRun.wait();
    }
    

     

     

    🔍 Notes

     

    • Replace SalesOrderQuery with your actual query name.

    • Ensure the form name (SalesTable) matches the menu item you're targeting.

    • This code should be triggered from a menu item of type Action, pointing to your controller class.


    •  
     

    This approach allows you to dynamically filter the Sales Order form based on user input without exposing batch processing.

     

    Thanks and best regards,\
    Daniele\
    Note: This response was prepared with support from Copilot to ensure clarity and completeness.

  • Sohaib Cheema Profile Picture
    48,972 User Group Leader on at
    open form with filtration by code x++
    As you do not understand the architecture of system, please do not post replies without context. You have no idea about how this business system works. you have posted the code about opening any form? you have no idea about how interaction classes work with List Pages. I would be surprised to know if you even know what is a list page and how the queries are working behind those list pages. Pleas do not be copy/paste from ChatGpt. Allow us to breath and work please.
    Could you show us the your query please. You can post about what datasources it has, what are the joins and all.
    Thank you
     
  • Suggested answer
    Martin Dráb Profile Picture
    236,570 Most Valuable Professional on at
    open form with filtration by code x++
    The idea of using the SysOperation framework for that isn't a good one. Your requirement has little to with what SysOperation framework is for and trying to use it would just make things more complicated for you. I'm assuming that you want to show the query filter dialog and you incorrectly believe that the SysOperation framework is the only way how to do. The correct solution is much easier - you can call prompt() method on any QueryRun object, such as the one used by SalesTable form. You can find quite a few examples in the standard application, e.g. in InventTransNew form.
     
    AI below came with an idea to completely replace the existing query, but it would be difficult (you'd have to re-implement the existing query) and risky (you make a mistake, the query may change, you break saved views and other features...). Don't artificial;y create all these problem when there is no reason for it. Also, the particular suggestion would merely allow users to set single values of three fields, but if you let user change the query in the query dialog, it will be much more powerful. They'll be able to select multiple customers, use wildcards, add other ranges and so on.
  • DELDYN Profile Picture
    434 on at
    open form with filtration by code x++
    Hi @Martin Dráb,

    you said i can call prompt function on any queryRun object like on salesTable From
    i went to the salesTable form and I'm not sure what u meant exactly

    so I think you are saying,  i should not use use sysOperationFramework but rather use a simple class that i can connect to the menu item where i can use queryRun and prompt, but can you please show me how? or guide me to the correct code?

    and when you mentioned InventTransNew form, is this another solution or similar to salesTable?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,771

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 542 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans