Category: Dynamics 365 F&O Codes

Sending Email using X++ Code (AX2012/D365)

class SRSendEmail_D365 {     public static void main(Args _args)     {         SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();         Email   toEmail;         Email   fromEmail;         try         {             FromEmail = “sreddy@xyzcompany.com”;             toEmail   = “tester@xyzcompany.com”;             messageBuilder.setBody(“Hello from D365”, false);             messageBuilder.setSubject(“Email Test from D365”);             messageBuilder.addTo(toEmail);             // Note: not calling setFrom() defaults to the current user for SMTP client, whereas             // when sent to Outlook any setFrom() value will be ignored since profiles on the client are used             messageBuilder.setFrom(fromEmail);             //…

DMF Metadata sample

<?xml version=”1.0″?> -<edmx:Edmx Version=”4.0″ xmlns:edmx=”http://docs.oasis-open.org/odata/ns/edmx”> -<edmx:DataServices> -<Schema Namespace=”Microsoft.Dynamics.DataEntities” xmlns=”http://docs.oasis-open.org/odata/ns/edm”> -<EntityType Name=”Customer”> -<Key> <PropertyRef Name=”CustId”/> </Key> -<Property Name=”CustId” Nullable=”false” Type=”Edm.Int32″> <Annotation String=”Customer Id” Term=”Microsoft.Dynamics.OData.Core.V1.LabelId”/> -<Annotation Term=”Microsoft.Dynamics.OData.Core.V1.AXType”> <EnumMember>Microsoft.Dynamics.OData.Core.V1.AXType/Int32</EnumMember> </Annotation> </Property> -<Property Name=”LocationName” Type=”Edm.String”> <Annotation String=”Location Name” Term=”Microsoft.Dynamics.OData.Core.V1.LabelId”/> -<Annotation Term=”Microsoft.Dynamics.OData.Core.V1.AXType”> <EnumMember>Microsoft.Dynamics.OData.Core.V1.AXType/String</EnumMember> </Annotation> </Property> -<Property Name=”State” Type=”Edm.String”> <Annotation String=”State” Term=”Microsoft.Dynamics.OData.Core.V1.LabelId”/> -<Annotation Term=”Microsoft.Dynamics.OData.Core.V1.AXType”> <EnumMember>Microsoft.Dynamics.OData.Core.V1.AXType/String</EnumMember> </Annotation> </Property> -<Property Name=”CustGroup” Type=”Edm.String”> <Annotation…

This is sample Code to get opening balance for Ledger Main account in Ax 2012.

LedgerBalanceMainAccountAmounts ledgerBalance; AmountMst opSum; ; ledgerBalance = LedgerBalanceMainAccountAmounts::construct(); ledgerBalance.parmIncludeRegularPeriod(true); ledgerBalance.parmIncludeOpeningPeriod(true); ledgerBalance.parmIncludeClosingPeriod(false); ledgerBalance.parmAccountingDateRange(mkDate(01,01,2000), mkDate(31,12,2017)); ledgerBalance.calculateBalance(MainAccount::findByMainAccountId(‘1123333’)); opSum = ledgerBalance.getAccountingCurrencyBalance(); info(num2str(opSum,10,2,1,1));

AX 2012: Clear the cache

In this post I would like to share the job. The purpose of this job is to clear Local Cache. Every time when I see doubtful behavior, I run this job to make sure that AX is not misbehave. static void RefreshLocalCache(Args _args) { xSession::removeAOC(); SysTreeNode::refreshAll(); SysFlushDictionary::main(null); SysFlushAOD::main(null); SysFlushData::main(null); SysBPCheckAIFDataObject::flushCache(true); SysFlushReportServer::main(null); SysFlushSystemSequence::main(null); xSession::updateAOC(); info(“ok”);

Upload and read CSV files in Dynamics 365 for operations

To quickly reuse the code here it goes class RGReadSample { /// /// Runs the class with the specified arguments. /// /// The specified arguments. public static void main(Args _args) { AsciiStreamIo                                   file; Array                                           fileLines; FileUploadTemporaryStorageResult                fileUpload; fileUpload = File::GetFileFromUser() as FileUploadTemporaryStorageResult; file = AsciiStreamIo::constructForRead(fileUpload.openResult()); if (file) { if (file.status()) { throw error(“@SYS52680”); } file.inFieldDelimiter(‘,’); file.inRecordDelimiter(‘\r\n’);…

How about running custom X++ scripts without any down time?

In 10.0.25 you can run simple X++ scripts on a production environment without any downtime. This feature lets you run custom X++ scripts without having to go through Dynamics LCS or suspend your system. Therefore, you can correct minor data inconsistencies without causing any disruptive downtime.   Video: https://www.linkedin.com/posts/michael-pontoppidan-a0ab691_xpp-dynamics365fo-axapta-ugcPost-6894353785636888577-lpgJ/ Reference : https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/deployment/run-custom-scripts