Posts

Showing posts from September, 2021

Azure BLOB storage with Dynamics 365 FnO X++

Image
Part-1: Azure BLOB storage with Dynamics 365 for operations 25 May 2020|Azure and Dynamics With the introduction of cloud based applications, Dynamics has opened doors for seamless integration with Azure services. This blog is created to portray one such example of how Azure capability can be utilized within Dynamics 365 for Operations. Lets consider a common scenario where Dynamics 365 for Operations needs exchange of files between different applications. This can be a file produced by your .Net application (or) it can be a file produced by you production system,etc,. In Dynamics AX 2012 this situation was handled by creating common folder and sharing in network path where different applications can place their files. Upon introduction of D365, local paths were not accessible by Dynamics production URL so we need to rely on common internet service for accessing the file. One of the convenient way to handle this situation is by using  Microsoft Azure BLOB storage  as the centra

Get Financial Dimensions using X++ - D365 FnO / Ax

 //function which returns the value of given dimension name e.g. BusinessUnit public str getDimensionDisplayValue(RecId defaultDimension, Name dimName) {   DimensionAttributeValueSetStorage dimStorage;   dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);   return dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(dimName).RecId); } //DefaultDimension is retrived from PurchTable just to give you an example. You can pass any DefaultDimension value //'Project' is the name of the financial dimension. You can use 'BusinessUnit', 'Worker' or 'CostCenter' etc. //call the function follows: str dimensionValue; dimensionValue = this.getDimensionDisplayValue(purchTable.DefaultDimension, 'Project')

Send Email from Ax / D365 FnO using X++

 static void SendEmail(Args _args) { SysEmailParameters parameters = SysEmailParameters::find(); SMTPRelayServerName relayServer; SMTPPortNumber portNumber; SMTPUserName userName; SMTPPassword password; Str1260 subject,body; InteropPermission interopPermission; SysMailer mailer; System.Exception e; ; if (parameters.SMTPRelayServerName) relayServer = parameters.SMTPRelayServerName; else relayServer = parameters.SMTPServerIPAddress; portNumber = parameters.SMTPPortNumber; userName = parameters.SMTPUserName; password = SysEmailParameters::password(); subject = "Subject line for the email"; body = "<B>Body of the email</B>"; CodeAccessPermission::revertAssert(); try { interopPermission = new InteropPermission(InteropKind::ComInterop); interopPermission.assert(); mailer = new SysMailer(); mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM); //instantiate email mailer.fromaddress("ax.notification@mycompany.com"); mailer.

Production ODATA Request - D365 FnO

As per Microsoft architecture for Production Environment you need to specially mention a cross company filter in the request query. For example, the request query should look like: {{resource}} /data/CustomersV3? cross-company=true &$format=json Below is the link for your reference for the similar issue :- Cross Company Filter Required for Fetching Records In Production

Get NextLink for OData from D365 FnO

Image
 To get the NextLink from Odata you need to add " Prefer " key in header and define "odata.maxpagesize" as shown in below API request

Create Xml using X++ - D365 FnO

 class My_XMLCreate {     /// <summary>     /// Runs the class with the specified arguments.     /// </summary>     /// <param name = "_args">The specified arguments.</param>     public static void main(Args _args)     {         XmlDocument xdoc;         XmlElement  xElement;         XmlElement  xTable, xNodeAccount, xNodeName;         MainAccount mainAccount;         #define.filename(@'C:\Temp\accounts.xml');         xdoc = XmlDocument::newBlank();         xElement =xdoc.createElement('xml');         xdoc.appendChild(xElement);         while select RecId, mainAccountId, Name from mainAccount         {             xTable = xdoc.createElement(tableStr(MainAccount));             xTable.setAttribute(fieldStr(MainAccount, RecId), int642Str(mainAccount.RecId));             xElement.appendChild(xTable);                          xNodeAccount = xdoc.createElement(fieldStr(MainAccount, MainAccountId));             xNodeAccount.appendChild(xdoc.c

Import Files from Blob storage using X++ - D365 FnO

 using Microsoft.WindowsAzure.Storage;  Using Microsoft.WindowsAzure.Storage.Blob;  class RunnableClassBlobStorageDownload  {      ///       /// Runs the class with the specified arguments.     ///       ///  The specified arguments.      public static void main(Args _args)      {          CloudBlobDirectory  cloudBlobDirectory;          CloudBlobClient  cloudBlobClient;          CloudBlobContainer  cloudBlobContainer;          CloudStorageAccount  cloudStorageAccount;          cloudStorageAccount  = CloudStorageAccount::Parse("Azure Blob Connection String");          cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();          cloudBlobContainer  = cloudBlobClient.GetContainerReference("files"); //           System.Collections.IEnumerable lstEnumarable =   cloudBlobContainer.ListBlobs(null, false, 0, null, null);          System.Collections.IEnumerator lstEnumarator = lstEnumarable.GetEnumerator();          List filenames = new List(Types::String);      

Export Xml To Blob Storage using X++ - D365 FnO

 using Microsoft.WindowsAzure.Storage;  Using Microsoft.WindowsAzure.Storage.Blob;  class RunnableClassBlobStorageUpload  {      ///       /// Runs the class with the specified arguments.     ///       ///  The specified arguments.      public static void main(Args _args)      {          System.Byte[] reportBytes = new System.Byte[0]();          System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();          reportBytes = enc.GetBytes("YOUR XML STRING/TEXT");          System.IO.MemoryStream stream = new System.IO.MemoryStream(reportBytes);          CloudBlobDirectory  cloudBlobDirectory;          CloudBlobClient  cloudBlobClient;          CloudBlobContainer  cloudBlobContainer;          CloudStorageAccount  cloudStorageAccount;          cloudStorageAccount  = CloudStorageAccount::Parse("DefaultEndpointsProtocol=https;AccountName=blobstorageazureservice;AccountKey=Q3zap5G1iU2GRyDQAmRF4z4hDMpPeJtj3AGfeOraiyPqFgzYrH3h59JIgFGSJX6sqTn/nbszsJHvrNz7KwfZKA==;EndpointSu