Hi Andre i don't know why it delete it my text.
So i had a class after creating a Purchase request and it being approved it sends an email to the user with a report with an email with the purchase ordre this is the code
[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()); }}
i debuged it and find out that purchId is not empty but purchTable is empty. i tried with PurchReqWFTypeEventHandler inside the completed methode but it's same thing.
any help please
[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);