Wednesday, September 19, 2018

Something went wrong while generating the report as an email D365FO

We sometimes get an error message when trying to send email using D365FO.



The issue sometimes is related with the email attached with the user being different from what SMTP server has access to send.

A workaround for this is to change the email for the user to the one which is mentioned in the SMTP setup.



The email mentioned in the email parameter setup can be used to update the user email.




Saturday, June 9, 2018

Know SQL query from entity in D365FO

If we need to find the SQL query from an entity we can create a new query and copy paste the datasource from entity to the new query and write below job to get the SQL query as a string.

class RunnableClasstest
{       
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {   
        query query;

        queryBuildDataSource    qbds;

        ;

        query = new Query(queryStr(querytest));

       info(query.dataSourceNo(1).toString());
    }

}

Saturday, May 26, 2018

Upload files into Azure Blob in D365FO/AX7

I was tasked with creating a mod where we need to attach files related to products which were coming from Azure Blob, so I created a C# library class to perform this activity. I attached the DLL as a reference to my project and I am calling each method accordingly as per the requirement. 

ConnectionString is nothing but AccountKey which we can get it from Azure Portal where we create the new Blob folder.

Using below code you can Upload,Download, View, Delete files from Azure blob.

using System;
using System.Collections.Generic;
using System.Linq;
//using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.IO;
//using Microsoft.WindowsAzure.Storage.Auth;
//using Microsoft.WindowsAzure.Storage.Core;
//using Microsoft.Azure.Management.DataFactories.Models;
//using Microsoft.Azure.Management.DataFactories.Runtime;

namespace BlobsStorageAssembly
{

    using Dynamics.AX.Application;
    public class AccessImageBlob
    {
        public List<string> ListBlobWithStorageClientLibrary(String _subFolder, String _product, String _rootFolder, String _connectionString)
        {
    
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_connectionString);

            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            var backupContainer = blobClient.GetContainerReference(_rootFolder);
            var listOfFileNames = new List<string>();
            var list = backupContainer.ListBlobs(_subFolder + "/" + _product, useFlatBlobListing: true);
            foreach (var blob in list)
            {
                listOfFileNames.Add(blob.Uri.ToString());
            }

            return listOfFileNames;
        }

        public void deleteImageFile(String _subFolder, String _product, String _rootFolder, String _connectionString)
        {

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_connectionString);

            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            var backupContainer = blobClient.GetContainerReference(_rootFolder);
            
           
            var list = backupContainer.ListBlobs(_subFolder + "/" + _product, useFlatBlobListing: true);

            if (list == null || list.Count() == 0)
            {
                return;
            }
            foreach (IListBlobItem blob in list)
            {
                String fileName = Path.GetFileName(blob.Uri.ToString());
                ICloudBlob cloudBlob = backupContainer.GetBlobReferenceFromServer(_subFolder + "\\" +fileName,null,null,null);
                cloudBlob.FetchAttributes();
                
                cloudBlob.DeleteIfExists();
            }
           
        }

        public void UploadToAzureStorage(System.IO.Stream streams,String _fileNamePath, String _rootFolder, String _subFolder, String _connectionString)
        {
            
            Task t = this.UploadToAzureStorageInner(streams, _fileNamePath,  _rootFolder,  _subFolder,  _connectionString);
        }

        public async Task UploadToAzureStorageInner(System.IO.Stream streams,String _fileNamePath, String _rootFolder, String _subFolder, String _connectionString)
        {
            string filename;
            CloudStorageAccount storageAccount =
                          CloudStorageAccount.Parse(_connectionString);

            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            var backupContainer = blobClient.GetContainerReference(_rootFolder);


            Uri uri = new Uri(_fileNamePath);

            filename = System.IO.Path.GetFileName(uri.LocalPath);
            CloudBlockBlob blockBlob = backupContainer.GetBlockBlobReference(_subFolder + "\\" + filename);

            await blockBlob.UploadFromStreamAsync(streams);

        }
    

    }
    
}

Wednesday, April 18, 2018

Database logging issue in D365/AX 7

I have recently come across an issue where I was adding 'currency' field into 'VentTable' for database logging, although the log was getting created the new selected field in setup which was 'currency' was not logging. This was a strange behavior, as the log was getting generated but the change values were blank.

Fix: I analysed and found that sometimes for the database log to work we need to unchecked all the fields from that table (VendTable) and end the setup. Once we are done we must again start the setup and this time add all the required fields including the new field(Currency) we want to add into the database log. This way I was able  to log all the fields.