Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Printing an invoice reg.

Posted on by 560

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

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
  • AXTechie2120 Profile Picture
    AXTechie2120 560 on at
    RE: Printing an invoice reg.

    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
    Rustem Galiamov 8,072 on at
    RE: Printing an invoice reg.

    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
    AXTechie2120 560 on at
    RE: Printing an invoice reg.

    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
    Rustem Galiamov 8,072 on at
    RE: Printing an invoice reg.

    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
    AXTechie2120 560 on at
    RE: Printing an invoice reg.

    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
    Rustem Galiamov 8,072 on at
    RE: Printing an invoice reg.

    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
    AXTechie2120 560 on at
    RE: Printing an invoice reg.

    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
    Rustem Galiamov 8,072 on at
    RE: Printing an invoice reg.

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

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


  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: Printing an invoice reg.

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans