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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Printing an invoice reg.

(0) ShareShare
ReportReport
Posted on by 568

Hi everyone,

Good day.

I am trying to save the pdf in my local machine whenever i invoice my sales order, everything is working fine but Its printing all sales orders of all customers,

What i want is to print the sales order for that customer only,I tried passing salesid and working good.

But i getting error in one point in my code,Like this,

---------------------------
Microsoft Dynamics AX Debugger
---------------------------
Error executing code: CustInvoiceContract object does not have method 'parmCustInvoiceDuplicateRecId'.

Stack trace

(C)\Classes\CustInvoiceContract\parmCustInvoiceDuplicateRecId
(C)\Forms\SalesEditLines\Methods\closeOk - line 36
(C)\Classes\FormRun\task
(C)\Forms\SalesEditLines\Methods\task - line 11
(C)\Classes\SysSetupFormRun\task - line 20
---------------------------
OK
---------------------------

I have copied my code below here,

public String255 export(SalesId  salesid)
{
    SalesInvoiceController          salesinvoicecontroller;
    SalesInvoiceContract            salesinvoicecontract;
    SrsPrintMgmtExecutionInfo       srsprintmgmtexecutioninfo;
    Args                            args = new Args();
    SrsReportRunImpl                srsreportrunimpl;
    CustInvoiceJour                 custinvoicejour;
    ReportName                      ReportName = "CustInvoice.Report";
    SalesTable                      salestable;
    SalesParmTable                  salesparmtable;


    while select  salesparmtable
        where  salesparmtable.SalesId  == salesid

    {

    args.record(salesparmtable);
    salesinvoicecontroller = new SalesInvoiceController();
    salesinvoicecontroller.parmReportName(ReportName);
   // srsprintmgmtexecutioninfo = salesinvoicecontroller.parmReportContract().parmReportExecutionInfo() as SrsPrintMgmtExecutionInfo;
    srsprintmgmtexecutioninfo = SalesInvoiceController.parmReportContract().parmReportExecutionInfo() as SrsPrintMgmtExecutionInfo;
    if(!srsprintmgmtexecutioninfo)
    {
       srsprintmgmtexecutioninfo = new SrsPrintMgmtExecutionInfo();
    }

    srsprintmgmtexecutioninfo.parmOriginalDestinationFileName("c:\\SR_SalesInvoice.pdf");
    salesinvoicecontract = salesinvoicecontroller.parmReportContract().parmRdpContract();
    salesinvoicecontract.parmCustInvoiceDuplicateRecId(salesparmtable.RecId);
    salesinvoicecontract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
    SalesInvoiceController.parmArgs(args);
    srsreportrunimpl = salesinvoicecontroller.parmReportRun() as SrsReportRunImpl;
    SalesInvoiceController.parmReportRun(srsreportrunimpl);
    SalesInvoiceController.parmReportContract().parmReportExecutionInfo(srsprintmgmtexecutioninfo);
    SalesInvoiceController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);
    SalesInvoiceController.parmReportContract().parmPrintSettings().overwriteFile(true);
    SalesInvoiceController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
    SalesInvoiceController.parmReportContract().parmPrintSettings().fileName("C:\\Users\\bharathk\\Downloads\\New folder\\salesinvoice_BK.pdf");
    SalesInvoiceController.runReport();
    //info("Report exported to a file");

    }
        return "";
}


Please advise,

Regards,

AX Techie 2120

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    Hi AXTechie2120!

    This line of code initialize  SalesInvoiceContract as CustInvoiceContract and there is no parmCustInvoiceDuplicateRecId() method

    salesinvoicecontract = salesinvoicecontroller.parmReportContract().parmRdpContract();

    Screenshot-2018_2D00_10_2D00_29-at-12.49.54.png
  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    I don't see where you are using SalesInvoiceContract except this:

    salesinvoicecontract = salesinvoicecontroller.parmReportContract().parmRdpContract();
    salesinvoicecontract.parmCustInvoiceDuplicateRecId(salesparmtable.RecId);
    salesinvoicecontract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());


  • AXTechie2120 Profile Picture
    568 on at

    Thanks for your reply,

    Can i know, why that custinvoicecontract class is initialized instead of the salesinvoicecontract contract,Please advise on how to save a single sales order in pdf format.

    Regards,

    AX Techie 2120

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    Because of this:

    ReportName  reportName = "CustInvoice.Report";


    Try to change CustInvoice.Report to SalesInvoice.Report


    And i think you should use CustInvoiceJour instead of SalesParmTable.

  • AXTechie2120 Profile Picture
    568 on at

    Hi,

    I made all  changes you have specified,but i am still facing another issue

    A currency to convert from is required to retrieve exchange rate information.

    I get the above error,

    I checked the header and lines for the sales order and in both the currency rates look good.

    Any advise please?

    Regards

    AX Techie 2120

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    You're getting this error because you don't set custInvoiceJour record to SalesInvoiceController.

    Try to use SalesInvoiceContract like this:

    salesInvoiceContract  = new SalesInvoiceContract();
    salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);
    salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
    salesInvoiceController.parmReportContract().parmRdpContract(salesInvoiceContract); 
  • AXTechie2120 Profile Picture
    568 on at

    Hi Rustem,

    I have specified requirements not specifically in the above,

    below is my requirement

    whenever we create a sales order and invoice button is clicked i want the pdf to be sent,but i have been trying with the above code for last 4 days but i cant figure it out,

    Please advise on how to achieve that,

    I am able to save invoiced sales order into pdf by a job.But i want to be done using   "Ok" button in the FORM "SalesEditLInes" .

    Please advise.

    Regards,

    AXTechie

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    Hi AXTechie2120!

    You can try to call your code in SalesFormLetter class's main() method after salesFormLetter.run().

    You should check parmEnum == DocumentStatus::Invoice condition. To get the CustInvoiceJour record use outputContract.parmJournal().

    But, you also need to create some parameter. When the parameter is setted - call your code.

  • AXTechie2120 Profile Picture
    568 on at

    Hi,

    I  tried this ,

    static void SR_SaveReportToPDFFromController1(Args _args)

    {

       SalesInvoiceController  salesInvoiceController;

       SalesInvoiceContract    salesInvoiceContract;

       Args                    args = new Args();

       SrsReportRunImpl        srsReportRun;

       CustInvoiceJour         custInvoiceJour;

       ReportName              reportName = "SalesInvoice.Report";

       SrsPrintMgmtExecutionInfo   reportExecutionInfo;

       ;

       select firstOnly custInvoiceJour;

       args.record(custInvoiceJour);

       salesInvoiceController = new SalesInvoiceController();

       salesInvoiceController.parmReportName(reportName);

       reportExecutionInfo = salesInvoiceController.parmReportContract().parmReportExecutionInfo()  as SrsPrintMgmtExecutionInfo;

       if(!reportExecutionInfo)

       {

           reportExecutionInfo = new SrsPrintMgmtExecutionInfo();

       }

       reportExecutionInfo.parmOriginalDestinationFileName("c:\\SR_SalesInvoice.pdf");

       salesInvoiceContract = salesInvoiceController.parmReportContract().parmRdpContract();

       salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty

       salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release

       salesInvoiceController.parmArgs(args);

       srsReportRun = salesInvoiceController.parmReportRun() as SrsReportRunImpl;

       salesInvoiceController.parmReportRun(srsReportRun);

       salesInvoiceContract.parmDocumentTitle("Invoice");

       salesInvoiceController.parmReportContract().parmReportExecutionInfo(new SrsPrintMgmtExecutionInfo());

       salesInvoiceController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);

       salesInvoiceController.parmReportContract().parmPrintSettings().overwriteFile(true);

       salesInvoiceController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);

       salesInvoiceController.parmReportContract().parmPrintSettings().fileName("C:\\Users\\bharathk\\Desktop\\SR_SalesInvoice.pdf");

       info("Report Saved");

       SalesInvoiceController.runReport();

    }

    but i am getting error like this,

    "The permissions granted to user 'domain\username' are insufficient for performing this operation.

    I searched in google but cant find any solution."

    But for below code,this is working fine,

    i dont know where its going wrong

    ProjInvoiceController       ProjInvoiceController;

      PSAProjInvoiceContract      PSAProjInvoiceContract;

      SrsPrintMgmtExecutionInfo   reportExecutionInfo;

      Args                        args = new Args();

      SrsReportRunImpl            srsReportRun;

      ProjInvoiceJour             ProjInvoiceJour;

      ReportName                  reportName = "PSAProjInvoice.Report";

      select firstOnly ProjInvoiceJour;

      args.record(ProjInvoiceJour);

      ProjInvoiceController = new ProjInvoiceController();

      ProjInvoiceController.parmReportName(reportName);

      reportExecutionInfo = ProjInvoiceController.parmReportContract().parmReportExecutionInfo() as SrsPrintMgmtExecutionInfo;

       if (!reportExecutionInfo)

      {

          reportExecutionInfo = new SrsPrintMgmtExecutionInfo();

      }

      reportExecutionInfo.parmOriginalDestinationFileName("c:\\SR_SalesInvoice.pdf");

      PSAProjInvoiceContract = ProjInvoiceController.parmReportContract().parmRdpContract();

      PSAProjInvoiceContract.parmProjInvoiceJourRecId(ProjInvoiceJour.RecId);

      PSAProjInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());

      ProjInvoiceController.parmArgs(args);

      srsReportRun = ProjInvoiceController.parmReportRun() as SrsReportRunImpl;

      ProjInvoiceController.parmReportRun(srsReportRun);

       PSAProjInvoiceContract.parmReportTitle("Invoice");

      ProjInvoiceController.parmReportContract().parmReportExecutionInfo(reportExecutionInfo);

      ProjInvoiceController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);

      ProjInvoiceController.parmReportContract().parmPrintSettings().overwriteFile(true);

      ProjInvoiceController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);

      ProjInvoiceController.parmReportContract().parmPrintSettings().fileName("C:\\Users\\bharathk\\Desktop\\salesinvoice.pdf");

      ProjInvoiceController.runReport();

      info('Report exported to file');

    PLease advise.

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
GiacomoRovai Profile Picture

GiacomoRovai 4

#3
Douglas Noel Profile Picture

Douglas Noel 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans