[ExtensionOf(ClassStr(PurchAutoCreate_PurchReq))]final class PurchAutoCreate_PurchReq_Class_Extension{ public Email xxgetRequisitionerEmail() { Purchreqline purchReqLine; HcmWorker hcmWorker; Email email; DirPersonUser dirPersonUser; UserInfo userInfo; select purchReqLine where purchReqLine.purchId == purchTable.purchId; dirPersonUser = HcmWorker::findPersonUser(HcmWorker::find(purchReqLine.Requisitioner).RecId); select firstonly userInfo where userInfo.Id == dirPersonUser.User; return userInfo.networkAlias; } public void create() { next create(); this.xxSendMail(purchTable.purchId, this.xxgetRequisitionerEmail()); } void xxSendMail(PurchId _purchId, Email _toEmail) { PurchTable purchTable = PurchTable::find(_purchId); Filename fileName = strFmt(/BC%1.pdf/, _purchId); xxPurchaseOrderReportController controller = new xxPurchaseOrderReportController(); xxPurchaseOrderReportContract contract = new xxPurchaseOrderReportContract(); SRSPrintDestinationSettings settings; Array arrayFiles; System.Byte[] reportBytes = new System.Byte[0](); SRSProxy srsProxy; SRSReportRunService srsReportRunService = new SrsReportRunService(); Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray; Map reportParametersMap; SRSReportExecutionInfo executionInfo = new SRSReportExecutionInfo(); //set the report contract parameters contract.parmPurchId(purchTable.PurchId); //set the report controller paramters //controller.parmArgs(_args); //set report name and desing name controller.parmReportName(ssrsReportStr(xxPurchaseOrderReport, report)); controller.parmShowDialog(false); controller.parmLoadFromSysLastValue(false); controller.parmReportContract().parmRdpContract(contract); // Provide printer settings settings = controller.parmReportContract().parmPrintSettings(); settings.printMediumType(SRSPrintMediumType::File); settings.fileName(fileName); settings.fileFormat(SRSReportFileFormat::PDF); // Below is a part of code responsible for rendering the report controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration()); controller.parmReportContract().parmReportExecutionInfo(executionInfo); srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName()); srsReportRunService.preRunReport(controller.parmreportcontract()); reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract()); parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap); srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig()); // Actual rendering to byte array reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),parameterValueArray,settings.fileFormat(),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(); } System.Byte[] binData1; System.IO.Stream stream1; // 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 sending settings var mail = SysMailerFactory::getNonInteractiveMailer(); var messageBuilder = new SysMailerMessageBuilder(); str body = strFmt(/%1 </b> %2 <br> / + /%3 </b> %4 <br> / + /%5 </b> <br> / + /%6 </b> <br> /, /@xxLabels:xxSendMail/, /,/, /@xxLabels:xxObject/, _purchId, /@xxLabels:xxAttach/, /@xxLabels:crdt/) ; messageBuilder.reset().setFrom('Dynamics365@xx.onmicrosoft.com') // From email address .addTo(_toEmail) // To Email address .setSubject(strFmt(/@xxLabels:xxNumber/, _purchId, purchTable.vendorName())) // Email Subject .setBody(body); //Email Body if (stream1 != null) { //add attachment to the email messageBuilder.addAttachment(stream1,filename); } //send email mail.sendNonInteractive(messageBuilder.getMessage()); }}
[ExtensionOf(classStr(PurchReqWFTypeEventHandler))]final class PurchReqWFTypeEventHandler_xx_Extension{ public void completed(WorkflowEventArgs _workflowEventArgs) { PurchReqTable purchReqTable; PurchLine purchLine; PurchTable purchTable; Purchreqline purchReqLine; HcmWorker hcmWorker; Email email; DirPersonUser dirPersonUser; UserInfo userInfo; next completed(_workflowEventArgs); WorkflowContext workflowContext = _workflowEventArgs.parmWorkflowContext(); purchReqTable = PurchReqTable::find(workflowContext.parmRecId()); select purchLine where purchReqTable.PurchReqId == purchLine.PurchReqId; purchTable = purchLine.purchTable(); select purchReqLine where purchReqLine.purchId == purchTable.purchId; dirPersonUser = HcmWorker::findPersonUser(HcmWorker::find(purchReqLine.Requisitioner).RecId); select firstonly userInfo where userInfo.Id == dirPersonUser.User; //this.xxSendMail(purchTable, userInfo.networkAlias);
[ExtensionOf(ClassStr(PurchAutoCreate_PurchReq))] final class PurchAutoCreate_PurchReq_Class_Extension { public Email xxgetRequisitionerEmail() { Purchreqline purchReqLine; HcmWorker hcmWorker; Email email; DirPersonUser dirPersonUser; UserInfo userInfo; select purchReqLine where purchReqLine.purchId == purchTable.purchId; dirPersonUser = HcmWorker::findPersonUser(HcmWorker::find(purchReqLine.Requisitioner).RecId); select firstonly userInfo where userInfo.Id == dirPersonUser.User; return userInfo.networkAlias; } public void create() { next create(); this.xxSendMail(purchTable.purchId, this.xxgetRequisitionerEmail()); } void xxSendMail(PurchId _purchId, Email _toEmail) { PurchTable purchTable = PurchTable::find(_purchId); Filename fileName = strFmt("BC%1.pdf", _purchId); xxPurchaseOrderReportController controller = new xxPurchaseOrderReportController(); xxPurchaseOrderReportContract contract = new xxPurchaseOrderReportContract(); SRSPrintDestinationSettings settings; Array arrayFiles; System.Byte[] reportBytes = new System.Byte[0](); SRSProxy srsProxy; SRSReportRunService srsReportRunService = new SrsReportRunService(); Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray; Map reportParametersMap; SRSReportExecutionInfo executionInfo = new SRSReportExecutionInfo(); //set the report contract parameters contract.parmPurchId(purchTable.PurchId); //set the report controller paramters //controller.parmArgs(_args); //set report name and desing name controller.parmReportName(ssrsReportStr(xxPurchaseOrderReport, report)); controller.parmShowDialog(false); controller.parmLoadFromSysLastValue(false); controller.parmReportContract().parmRdpContract(contract); // Provide printer settings settings = controller.parmReportContract().parmPrintSettings(); settings.printMediumType(SRSPrintMediumType::File); settings.fileName(fileName); settings.fileFormat(SRSReportFileFormat::PDF); // Below is a part of code responsible for rendering the report controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration()); controller.parmReportContract().parmReportExecutionInfo(executionInfo); srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName()); srsReportRunService.preRunReport(controller.parmreportcontract()); reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract()); parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap); srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig()); // Actual rendering to byte array reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),parameterValueArray,settings.fileFormat(),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(); } System.Byte[] binData1; System.IO.Stream stream1; // 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 sending settings var mail = SysMailerFactory::getNonInteractiveMailer(); var messageBuilder = new SysMailerMessageBuilder(); str body = strFmt( "%1 </b> %2 <br> " + "%3 </b> %4 <br> " + "%5 </b> <br> " + "%6 </b> <br> ", "@xxLabels:xxSendMail", ",", "@xxLabels:xxObject", _purchId, "@xxLabels:xxAttach", "@xxLabels:crdt") ; messageBuilder.reset().setFrom('Dynamics365@xx.onmicrosoft.com') // From email address .addTo(_toEmail) // To Email address .setSubject(strFmt("@xxLabels:xxNumber", _purchId, purchTable.vendorName())) // Email Subject .setBody(body); //Email Body if (stream1 != null) { //add attachment to the email messageBuilder.addAttachment(stream1,filename); } //send email mail.sendNonInteractive(messageBuilder.getMessage()); } }
[ExtensionOf(classStr(PurchReqWFTypeEventHandler))] final class PurchReqWFTypeEventHandler_xx_Extension { public void completed(WorkflowEventArgs _workflowEventArgs) { PurchReqTable purchReqTable; PurchLine purchLine; PurchTable purchTable; Purchreqline purchReqLine; HcmWorker hcmWorker; Email email; DirPersonUser dirPersonUser; UserInfo userInfo; next completed(_workflowEventArgs); WorkflowContext workflowContext = _workflowEventArgs.parmWorkflowContext(); purchReqTable = PurchReqTable::find(workflowContext.parmRecId()); select purchLine where purchReqTable.PurchReqId == purchLine.PurchReqId; purchTable = purchLine.purchTable(); select purchReqLine where purchReqLine.purchId == purchTable.purchId; dirPersonUser = HcmWorker::findPersonUser(HcmWorker::find(purchReqLine.Requisitioner).RecId); select firstonly userInfo where userInfo.Id == dirPersonUser.User; //this.xxSendMail(purchTable, userInfo.networkAlias);
void hpsSendMail(PurchTable _purchTable, Email _toEmail) { PurchId _purchId = _purchTable.PurchId; PurchTable purchTable = _purchTable;//PurchTable::find(_purchId);
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 683 Most Valuable Professional
André Arnaud de Cal... 563 Super User 2025 Season 2
Sohaib Cheema 398 User Group Leader