Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How to filter form data source only when calling the form through action menu item

(1) ShareShare
ReportReport
Posted on by 45

Here  i have a action menu item control (Auto create purchase order) in my salesTableListpage form. when calling this menu item i want to filter the record in the corres ponding form(purch create fron sales order)  based on my conditon. 

here i write a my code in  purchcreate datasource execute query method using coc

here my problem is that when iam calling the query it affects the stf functionaties..how i can filter the record only when i  calling the menuitem

public void executeQuery()
{

QueryBuildDataSource qbdsSalesline;
QueryBuildDataSource qbdsInventTable;
QueryBuildRange qbrAutoPurchCreation;
FormRun formRun;
SalesLine salesLine;
SalesTable salesTable;
InventTableModule inventTable;
MenuFunction menuFunction;
Args args = new Args();
Common callerRecord;
QueryRun queryRun;
PurchCreateFromSalesOrder purForm;


qbdsSalesline = this.query().dataSourceTable(tableNum(SalesLine));
qbdsInventTable = qbdsSalesline.addDataSource(tableNum(InventTableModule));
qbdsInventTable.relations(false);
qbdsInventTable.addLink(fieldNum(InventTableModule, ItemId), fieldNum(SalesLine, ItemId));


qbdsInventTable.addRange(fieldNum(InventTableModule, AutoCreatePO)).value(strFmt("%1", NoYes::Yes));

next executeQuery();

}

  • Martin Dráb Profile Picture
    Martin Dráb 230,994 Most Valuable Professional on at
    RE: How to filter form data source only when calling the form through action menu item

    Then you know why your code doesn't work. It assumes that the form is called by your menu item, but it isn't. It's called by the class.

    You need to pass the information from the menu item to the class (in initializeFromArgs()) and then from the class to the form.

  • deepak31 Profile Picture
    deepak31 45 on at
    RE: How to filter form data source only when calling the form through action menu item

    Yes it is a class only. Through the class they are calling a form. I need to filter that form .

    when i am clicking the action menu item "Auto purchase order creation "the filter should works on the form that called by the class

    .

  • Martin Dráb Profile Picture
    Martin Dráb 230,994 Most Valuable Professional on at
    RE: How to filter form data source only when calling the form through action menu item

    The standard Purchase order button uses PurchCreateFromSalesorderSales menu item, which opens PurchCreateFromSalesOrder class, not a form.

  • Martin Dráb Profile Picture
    Martin Dráb 230,994 Most Valuable Professional on at
    RE: How to filter form data source only when calling the form through action menu item

    What do you mean by "another" form? Are you saying that you menu item opens a different form than where you placed your code?

  • deepak31 Profile Picture
    deepak31 45 on at
    RE: How to filter form data source only when calling the form through action menu item

    No.its not entering  into the if condition  .here iam not able to access the menuitem.bcz the menuitem is from another form..how i can correctly call the menuitem.....

  • Alex VN Profile Picture
    Alex VN 1,994 on at
    RE: How to filter form data source only when calling the form through action menu item

    Have you try to debug this code, did the process enter the if statement?

  • deepak31 Profile Picture
    deepak31 45 on at
    RE: How to filter form data source only when calling the form through action menu item

    here my requirement is

    Create a new button ‘Auto create purchase order’ in Sales order header as same as the
    standard functionality ‘Purchase order’. Use the custom functionality on Sales order -> Auto
    create purchase order, to auto create the Purchase order for the included lines.
    Accounts receivable > orders > All sales orders and select the sales order number.
     Add lines to the sales order. And click on ‘Auto create purchase order’ from the new menu.

    The form displays only the items for which the Auto Create Purchase order flag was enabled.
    .
    ï‚· The PO should be auto confirmed once it is created successfully.

  • Martin Dráb Profile Picture
    Martin Dráb 230,994 Most Valuable Professional on at
    RE: How to filter form data source only when calling the form through action menu item

    I'm sorry, but "its not working" can mean anything. Please describe your actual problem. Wait, I see a problem. You should call your code below next init() (I forgot to change that when converting your code from executeQuery()).

    By the way, your code is difficult to read because you pasted it in a wrong way. Always use Insert > Code (in the rich-formatting view). You can see the correct result in my previous reply.

  • deepak31 Profile Picture
    deepak31 45 on at
    RE: How to filter form data source only when calling the form through action menu item

    qbdsSalesline = this.queryBuildDataSource();

       qbdsInventTable = qbdsSalesline.addDataSource(tableNum(InventTableModule));

       qbdsInventTable.relations(false);

       qbdsInventTable.addLink(fieldNum(InventTableModule, ItemId), fieldNum(SalesLine, ItemId));

       SalesTable = this.formRun().args().record();

       if(this.formRun().args().menuItemName() == menuItemActionStr(IMPDPurchCreatewFromSalesOrder))

           {

               qbdsInventTable.addRange(fieldNum(InventTableModule, AutoCreatePO)).value(strFmt("%1", NoYes::Yes));

       ////qbdsInventTable.addRange(fieldNum(InventTableModule,AutoCreatePO )).value(SysQuery::value(NoYes::Yes));

           }

           next Init();

    here i tried this way to call the menu item and filter the record but its not working

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,994 Most Valuable Professional on at
    RE: How to filter form data source only when calling the form through action menu item

    First of all, notice the bug in your code. You're adding an extra data source ever time when the query gets executed, e.g. when a user sorts the grid. You should do it just once, in init().

    Also, most of your code does nothing. It can be reduced to mere this:

    public void init()
    {
    	next init();
    
    	QueryBuildDataSource qbdsSalesline = this.queryBuildDataSource();
    	QueryBuildDataSource qbdsInventTable = qbdsSalesline.addDataSource(tableNum(InventTableModule));
    	qbdsInventTable.relations(false);
    	qbdsInventTable.addLink(fieldNum(InventTableModule, ItemId), fieldNum(SalesLine, ItemId));
    
    	qbdsInventTable.addRange(fieldNum(InventTableModule, AutoCreatePO)).value(queryValue(NoYes::Yes));
    
    }

    To run your code just when a particular menu item is used, you can set a parameter on the menu item and check it in your code. You could also check the name of the menu item, but it's less flexible. If you want to use another menu item, you'd have to change the form too. If you use a parameter, you'll simply add a menu item with the right parameter value.

    By the way, are you sure you don't want to filter InventTableModule by ModuleType? And you can use an exists join instead of the inner join, because you don't need to fetch any data from this 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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,234 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,994 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans