Skip to main content

Notifications

Community site session details

Community site session details

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

To open report using selected sales order on clicking menu item button.

(0) ShareShare
ReportReport
Posted on by 1,479

I have created menu item button named "situationary declaration " in all sales order form so when i clicked on this button it will open the report 

with the dilogue box having invoice id parameter but i dont want that , what i want is 

if i open specific sales order and then click "situationary declaration " button it should directly open the report for that sales order which having invoice id .

no need of dilogue box is there report should directly open on click of menu item button.

can someone suggest how can i get this done.

pastedimage1672902369773v1.png

pastedimage1672902420233v2.png 

  • Dineshkarlekar Profile Picture
    1,479 on at
    RE: To open report using selected sales order on clicking menu item button.

    hi ,.

    thanks for the correction in code now i am getting required output now.

    thank you 

  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: To open report using selected sales order on clicking menu item button.

    Have you debugged the code and find out whether line number 32 returns salesId selected in the form?

    Also it seems select statement you have added to salesOrderExim table is wrong. No need of join. Refer to below code which I have modified.

    [ExtensionOf(formStr(SalesTable))]
     final class EximSalesForm_Extension
    {
        /// 
        ///
        /// 
        /// 
        /// 
        [FormControlEventHandler(formControlStr(SalesTable, Dev_SituationaryDeclaration), FormControlEventType::Clicked)]
        public static void Dev_SituationaryDeclaration_OnClicked(FormControl sender, FormControlEventArgs e)
        {
    
            SalesOrderExim                       salesOrderExim;
            CustInvoiceJour                      custInvoiceJour;
            SalesTable                           salesTable;
            InvoiceId                             _id;
            SalesId                              salesId;
    
            Args args = new Args();
    
            str parameterString;
            ;
    
            FormDataSource   salesTable_ds = sender.formRun().dataSource(1);
    
            args.caller(salesTable_ds);
    
            salesTable   = salesTable_ds.cursor();
    
            select * from salesOrderExim
                where salesOrderExim.RefrenceRecId == salesTable.RecId;
            args.record(salesOrderExim);
    
            args.parm(salesOrderExim.InvoiceId);   
           
            
            new MenuFunction(menuItemDisplayStr(Dev_SituationaryDeclarationMnu), MenuItemType::Display).run(args);
            
    
        }
    
    }

    Thanks,

    Girish S.

  • Dineshkarlekar Profile Picture
    1,479 on at
    RE: To open report using selected sales order on clicking menu item button.

    hi , thanks for helping me out with code , I am getting  report generated in output ,but my report is selecting first record from "salesorderexim" table but i want to get the report of sales id which  i select in salesorder form , how can i get it deone can you plz help me out.

    [ExtensionOf(formStr(SalesTable))]
     final class EximSalesForm_Extension
    {
        /// 
        ///
        /// 
        /// 
        /// 
        [FormControlEventHandler(formControlStr(SalesTable, Dev_SituationaryDeclaration), FormControlEventType::Clicked)]
        public static void Dev_SituationaryDeclaration_OnClicked(FormControl sender, FormControlEventArgs e)
        {
    
            SalesOrderExim                       salesOrderExim;
            CustInvoiceJour                      custInvoiceJour;
            SalesTable                           salesTable;
            InvoiceId                             _id;
            SalesId                              salesId;
    
            Args args = new Args();
    
            str parameterString;
            ;
    
            args.record(salesOrderExim);
    
            args.parm(salesOrderExim.InvoiceId);
     
            FormDataSource   salesTable_ds = sender.formRun().dataSource(1);
    
            args.caller(salesTable_ds);
    
            salesTable   = salesTable_ds.cursor();
    
            select * from salesOrderExim
                join salesTable 
                where  salesTable.RecId == salesOrderExim.RefrenceRecId;
               
           
            
                new MenuFunction(menuItemDisplayStr(Dev_SituationaryDeclarationMnu), MenuItemType::Display).run(args);
            
    
        }
    
    }

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: To open report using selected sales order on clicking menu item button.

    args.caller() will expect type Object. You are trying to pass the string field to caller method which is wrong.

    Get the formRum from the FormControl and pass that as a argument to the caller method.

    args.caller(sender.formRun());

    Thanks,

    Girish S.

  • Dineshkarlekar Profile Picture
    1,479 on at
    RE: To open report using selected sales order on clicking menu item button.

    yes i will change the menu item to output type . but i am getting error in my code

    "Error Type mismatch in 'Args.caller' argument 1. The expected type is 'Object', but the actual type is 'str'."

    on this line 

        args.caller(salesOrderExim.InvoiceId);

     [FormControlEventHandler(formControlStr(SalesTable, Dev_SituationaryDeclaration), FormControlEventType::Clicked)]
        public static void Dev_SituationaryDeclaration_OnClicked(FormControl sender, FormControlEventArgs e)
        {
    
            SalesOrderExim                       salesOrderExim;
            CustInvoiceJour                      custInvoiceJour;
            SalesTable                           salesTable;
            Args args = new Args();
    
            str parameterString;
            ;
    
            args.record(salesOrderExim);
    
            args.caller(salesOrderExim.InvoiceId);
    
            select forupdate salesOrderExim
                where   salesOrderExim.RefrenceRecId == salesTable.RecId;
    
            if(salesTable.SalesStatus==SalesStatus::Invoiced)
            {
                select InvoiceId,InvoiceDate  from custInvoiceJour
                    where custInvoiceJour.SalesId == salesTable.SalesId;
    
                new MenuFunction(menuItemDisplayStr(Dev_SituationaryDeclarationMnu), MenuItemType::Display).run(args);
            }
    
        }

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: To open report using selected sales order on clicking menu item button.

    It will be better if you create new output menu item and map the controller classes to it.

    Thanks,

    Girish S.

  • Dineshkarlekar Profile Picture
    1,479 on at
    RE: To open report using selected sales order on clicking menu item button.

    i am using display  menu item for this is will this work with display menu item , what do you suggest about this .

    Thanks,

    regards Dinesh

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: To open report using selected sales order on clicking menu item button.

    You can do like that as I already mentioned in my previous reply about using the "prePromptModifyContract" method. Seems you have already done that, So please refers to the previous reply. Also you pasted the code for the same.

    But this can be done by editing the controller class - If the same report is used in other menus it will also get affected.

    Thanks,

    Girish S.

  • Dineshkarlekar Profile Picture
    1,479 on at
    RE: To open report using selected sales order on clicking menu item button.

    thanks for reply ,

    but i was looking for something like this

    https://www.bhsolutions.com/news/blog/how-to-launch-an-ssrs-report-from-ax-with-pre-loaded-parameters/

    can you suggest how can i modify my code  by reffering above link.

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: To open report using selected sales order on clicking menu item button.

    Refer to the below blog.

    https://community.dynamics.com/365/financeandoperations/b/goshoom/posts/printing-reports-from-code-in-d365fo

    On the above blog it will download this as file. To show it in screen just change the SRSPrintMediumType to "Screen"

    Thanks,

    Girish S.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,217 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,978 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans