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)

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

I have the same question (0)
  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    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.

  • AX QA Profile Picture
    115 on at

    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). 

  • Verified answer
    Brandon Wiese Profile Picture
    17,788 on at

    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
    115 on at

    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.

  • Brandon Wiese Profile Picture
    17,788 on at

    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.

  • Sathish_Chinnappan Profile Picture
    1,318 on at
    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());
    }
     

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
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans