Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

External Customer Account Statement using X++?

(0) ShareShare
ReportReport
Posted on by 115

Hi All,

I have used the following code to create the external customer account statement for one customer but when it creates file it is showing the wrong customer account number on report. For example; I ran report for customer account 'XXXX' but it prints customer account 'YYYY' on report.

Can anyone please tell me what I am missing here?

public void createCustAccountStatement()
{

CustTable custTable = CustTable::find('XXXX')
CustAccountStatementExtController controller = new CustAccountStatementExtController();
SRSPrintDestinationSettings printSettings;
CustAccountStatementExtContract Contract;

controller.parmReportName(PrintMgmtDocType::construct(PrintMgmtDocumentType::CustAccountStatement).getDefaultReportFormat());

Contract = controller.parmReportContract().parmRdpContract() as CustAccountStatementExtContract;

Contract.parmAgingBucket(agingBucket);
Contract.parmAgingBucketPrintDescription(AgingBucketPrintDescription);
Contract.parmAgingPeriod(agingPeriod);
Contract.parmCustAccount(custTable.AccountNum);
Contract.parmDayMonth(dayMonth);
Contract.parmFromDate(fromDate);
Contract.parmIncludeReversed(includeReversed);
Contract.parmManualSetup(manualSetup);
Contract.parmOnlyOpen(onlyOpen);
Contract.parmPrintAging(printAging);
Contract.parmPrintAmountGiro(printAmountGiro);
Contract.parmPrintCreditLimit(printCreditLimit);
Contract.parmPrintGiro(printGiro);
Contract.parmPrintingDirection(printingDirection);
Contract.parmPrintNonZero(printNonZero);
Contract.parmPrintPaymentSchedule(printPaymentSchedule);
Contract.parmPrintType(printType);
Contract.parmSpecifyDueToDate(specifyDueToDate);
Contract.parmToDate(toDate);

printSettings = controller.parmReportContract().parmPrintSettings();

printSettings.printMediumType(SRSPrintMediumType::File);
printSettings.fileFormat(SRSReportFileFormat::PDF);
printSettings.overwriteFile(true);
printSettings.fileName(AnyFilename);

controller.parmShowDialog(false);

controller.startOperation();
}

*This post is locked for comments

  • Sathish_Chinnappan Profile Picture
    Sathish_Chinnappan 1,307 on at
    External Customer Account Statement using X++?
    I can send email with customer statement pdf with no customer statement
    content. However, the content does exist by manually with the same
    parameters. Below is my code:


    controller.parmReportName(reportName);
    fileName = strFmt("SOA_%1.pdf",custTable.AccountNum);
    contract = controller.parmReportContract().parmRdpContract();
    contract.parmRecordId(custTable.RecId);  // Record id must be passed otherwise the report will be empty

    contract.parmFromDate(mkdate(1,1, 2000));
    contract.parmToDate(today());
    contract.parmOnlyOpen(true);
    contract.parmIncludeReversed(false);
    contract.parmPrintNonZero(true);
    contract.parmPrintPaymentSchedule(false);
    contract.parmPrintCreditLimit(true);
    contract.parmPrintAging(false);
    contract.parmAgingPeriod(false);
    contract.parmAgingBucketPrintDescription(false);


    contract.parmDayMonth(DayMonth::Day);
    contract.parmManualSetup(false);
    contract.parmPrintAmountGiro(false);
    contract.parmPrintGiro(PaymentStub::None);
    contract.parmPrintingDirection(ForwardBackwardPrinting::Forward);
    contract.parmPrintType("");
    contract.parmSpecifyDueToDate(dateNull());*/

    //contract.parmCustAccount(custTable.AccountNum);
    contract.parmCustAccountStatementExtTmp(custAccountStatementExtTmp.getPhysicalTableName());

    Query query;
    MapEnumerator enumerator;

    enumerator = controller.parmReportContract().parmQueryContracts().getEnumerator();
    enumerator.moveNext();
    query = enumerator.currentValue();
    query.dataSourceTable(tableNum(CustTable)).addRange(fieldNum(CustTable, AccountNum)).value(queryValue(custTable.AccountNum));

    srsReportRun = controller.parmReportRun() as SrsReportRunImpl;
    controller.parmReportRun(srsReportRun);
    controller.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);    // remove
    controller.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
    controller.parmReportContract().parmPrintSettings().fileName(fileName);
    controller.parmShowDialog(true);
    controller.parmReportContract().parmPrintSettings().overwriteFile(true);
    //controller.run();

    //SRSReportExecutionInfo executionInfo = new SRSReportExecutionInfo();
    controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
    controller.parmReportContract().parmReportExecutionInfo(executionInfo);


    srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());

    srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
    srsReportRunService.preRunReport(controller.parmreportcontract());
    reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract());
    parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);

    settings = controller.parmReportContract().parmPrintSettings();
    settings.printMediumType(SRSPrintMediumType::File);
    settings.fileName(fileName);
    //settings.parmEMailContract(emailContract);
    settings.fileFormat(SRSReportFileFormat::PDF);

    srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
    //Actual rendering to byte array
    reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),
    parameterValueArray,
    controller.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF),
    settings.deviceinfo());


    // You can also convert the report Bytes into an xpp BinData object if needed
    container binData;
    Binary binaryData;
    System.IO.MemoryStream mstream = new System.IO.MemoryStream(reportBytes);
    binaryData = Binary::constructFromMemoryStream(mstream);
    if(binaryData)
    {
    binData = binaryData.getContainer();
    }

    // Turn the Bytes into a stream
    for(int i = 0; i < conLen(binData); i++)
    {
    binData1 = conPeek(binData,i+1);
    stream1 = new System.IO.MemoryStream(binData1);
    }

    email = '';
    if(custTable.email() != '')
    {
    email = custTable.email();
    }
    else
    {
    email = CustParameters::find().CustomerSOACC;
    }

    if(email)
    {
    var messageBuilder = new SysMailerMessageBuilder();
    messageBuilder.setPriority(System.Net.Mail.MailPriority::High);
    messageBuilder.addTo(custTable.email())
    .addCc(CustParameters::find().CustomerSOACC)
    .setSubject(strFmt("%1 - %2", SysEmailMessageTable::find(CustParameters::find().CustomerSOAEmailITemp,"en-us").Subject, custTable.name()))
    .setBody(SysEmailMessageTable::find(sysEmailTable.EmailId,'en-us').Mail)
    .setFrom(sysEmailTable.SenderAddr ,sysEmailTable.SenderName);

    if (stream1 != null)
    {
    messageBuilder.addAttachment(stream1,fileName);
    }

    SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(messageBuilder.getMessage());
    }
     
  • Brandon Wiese Profile Picture
    Brandon Wiese 17,788 on at
    RE: External Customer Account Statement using X++?

    Sometimes you just have to pop the hood and look at how things work.  In this case, I used that customer statement report to learn how pre-processed print management reports worked, so I could write my own that worked the same way.  That's how I know immediately when I read your post that the .parmCustomer() was the problem.  The code I posted for how to update the query is a little sloppy and more proof of concept, but it does work.

  • AX QA Profile Picture
    AX QA 115 on at
    RE: External Customer Account Statement using X++?

    Thank you so much...it worked like a charm.

    How did you get this info...just wondering how can I learn more and get such type of information.

  • Verified answer
    Brandon Wiese Profile Picture
    Brandon Wiese 17,788 on at
    RE: External Customer Account Statement using X++?

    The .parmCustomer() method on the contract is hidden and used internally, and so it does not work to use it the way you have used it.  For most reports, it probably works fine as a regular parameter, just not here.

    Add these to your declarations.

       Query query;
    
       MapEnumerator enumerator;

    Then after the line where you get the contract from the controller, i.e. contract = controller.parmReportContract()..

    Add these lines.

       enumerator = controller.parmReportContract().parmQueryContracts().getEnumerator();
    
       enumerator.moveNext();
    
       query = enumerator.currentValue();
    
       query.dataSourceTable(tableNum(CustTable)).addRange(fieldNum(CustTable, AccountNum)).value(queryValue(custTable.AccountNum));

    Then remove the line below.

       contract.parmCustAccount(custtable.AccountNum);

    Hope this helps.

  • AX QA Profile Picture
    AX QA 115 on at
    RE: External Customer Account Statement using X++?

    I am running the above method from a class which opens a UI similar to customer account statement Ext report UI. I select customer account there using select button, I also override the queryRun method in my class.

    In Run() of class I retrieve customer account like this which is coming correct what I selected.

    while (queryRun.next())

    {

           custTable    =   queryRun.get(tableNum(custTable));

    fileName    =   WinAPI::getTempPath()+"Customer "+ custTable.AccountNum+ " Customer Account Statement.pdf";

               this.createCustAccountStatement(custTable, filename); // this method I explained you in above post

    }

    it comes into this method with correct customer account and when it calls the startOperation() of controller class it start generating files into above specified path + fileName. I also see it is also generating few folders for print management stuff which is running for all customers, don't why?

    What I have also experienced is that the first file which is created in above path (for me, it is at C:\Users\AX.QA\AppData\Local\Temp\2) is replacing with every new file generating in print management folders (ax.qa-CustAccountStatement-say20g33.end). 

  • Suggested answer
    Brandon Wiese Profile Picture
    Brandon Wiese 17,788 on at
    RE: External Customer Account Statement using X++?

    Since that is a pre-processed report, the contact uses the Customer parameter, .parmCustomer(), to splinter off one customer after another from the pre-processed data into what actually prints.

    You need to set the customer in the query.  If you run the report from the UI, you use the Select button to set the customer.  Adding the customer to the query as a range is the X++ equivalent.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,540 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans