Thursday, July 28, 2022

Run a class in batch Dynamics 365 FO

static void Job_ScheduleBatch2(Args _args)

{

     BatchHeader     batHeader;

     BatchInfo          batInfo;

     RunBaseBatch  rbbTask;

     str ParmCaption = "My Demonstration";

     ;

     rbbTask = new Batch4DemoClass();

     batInfo = rbbTask .batchInfo();

     batInfo .parmCaption(ParmCaption);

     batInfo .parmGroupId(""); // The "Empty batch group".

     batHeader = BatchHeader ::construct();

     batHeader .addTask(rbbTask);

     batHeader .save();

     info(strFmt("'%1' batch has been scheduled.", ParmCaption));

 }




class Batch4DemoClass extends RunBaseBatch

{

            public void run()

            {

                // The purpose of your job.

                info(strFmt("Hello from Batch4DemoClass .run at %1"

                    ,DateTimeUtil ::toStr(

                        DateTimeUtil ::utcNow())

                    ));

            }

            public container pack()

            {

                return conNull();

            }

            public boolean unpack(container packedClass)

            {

                return true;

            }

}


Link

Friday, July 22, 2022

Export CSV file to Microsoft Azure Storage in Dynamics 365 FO

using Microsoft.WindowsAzure.Storage;

using Microsoft.WindowsAzure.Storage.Auth;

using Microsoft.WindowsAzure.Storage.Blob;

Class ExportCSV

{

    public static void main(Args _args)

    {

        CommaStreamIo                       commaStreamIo;

        commaStreamIo = CommaStreamIo::constructForWrite();

        commaStreamIo.writeExp(['Name','Phone number']);

        commaStreamIo.writeExp(['Atul Yadav','9871286647']);


        System.IO.Stream stream = commaStreamIo.getStream();

        this.exportFileToAzureBlob(stream);

    }


    public void exportFileToAzureBlob(System.IO.Stream  _stream)

    {

        #define.dotcsv('.csv')

        #define.Underscore('_')

        MCOEDI888BlobParameters parameters = MCOEDI888BlobParameters::find();

        Filename    fileName;

        _stream.Position = 0;

        fileName = strfmt(parameters.FileName + #Underscore

                                        + date2str(DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()),213,2,0,2,0,4)

                                        + #Underscore

                                        + strRem(time2str(DateTimeUtil::getTimeNow(DateTimeUtil::getUserPreferredTimeZone()),2,TimeFormat::Hour24),'.')

                                        + #dotcsv);

        StorageCredentials storageCredentials = new StorageCredentials(parameters.AzureStorageAccount, parameters.AzureStorageKey);     //Account name and Azure storage key

        CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);

        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        CloudBlobContainer cont = blobClient.GetContainerReference(parameters.AzureBlobContainer);  //Name of the blob container where you want the file to be exported

        CloudBlockBlob cloudBlockBlob = cont.GetBlockBlobReference(fileName);

        cloudBlockBlob.UploadFromStream(_stream, null, null, null);

    }


}

Connection to Microsoft Azure Storage Explorer

Download and install "Microsoft Azure Storage Explorer"

Open it and click on the connect button as shown in the below picture


A new popup window will appear as below

Click on "Storage account and service" and select Account name and key as below


Now enter the Display name as per your need and the Account Name and Account Key as follows


Click on next, following window will popup


Now the old window will be closed and you can see the Storage account


When you will expand "Blob Containers", it will show all the existing blob containers.

Thursday, July 21, 2022

Joins in Dynamics 365

 Table A :


Table B :


Inner :


Outer :


Exist :


Not Exist :


Joins in SQL

Table A :

Table B :

Inner Join :


Left Outer :


Right Outer :


Full Outer Join :


Wednesday, July 20, 2022

Date to dateTimeUTC in Dynamics 365 FO

Date _Currentdate;

utcDateTime _UtcStartPeriod;

utcDateTime _UtcEndPeriod;

;

_currentdate=today();

_UtcCurrentPeriod =  DateTimeUtil::newDateTime(_currentdate,0);

_UtcEndPeriod = DateTimeUtil::newDateTime(_UtcEndPeriod,86400);

Friday, July 15, 2022

Layers in Dynamics 365 FO

The following describes the application object layers in Microsoft Dynamics 365:

USR - The user layer is for user modifications, such as reports.

CUS - The customer layer is for modifications that are specific to a company.

VAR - Value Added Resellers (VAR) can make modifications or new developments to the VAR layer as specified by the customers or as a strategy for creating an industry-specific solution.

ISV - When an Independent Software Vendor (ISV) creates its own solution, its modifications are saved in the ISV layer.

SLN - The solution layer is used by distributors to implement vertical partner solutions.

FPK - The FPK layer is an application object patch layer reserved by Microsoft for future patching or other updates. For more information, see Patch Layers.

GLS - When the application is modified to match country or region-specific legal demands, these modifications are saved in the GLS layer.

SYS - The standard application is implemented at the lowest level, the SYS layer. The application objects in the standard application can never be deleted.

Wednesday, July 13, 2022

How to add a C# class in Dynamics 365 FO

 Create a C# project in visual studio like below




Add the following class in your project area

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AYDotNet
{
    public class Calculator
    {
        public decimal Add(decimal x, decimal y)
        {
            return x + y;
        }
    }
}

Now build the project and not the solution.


Once that is done, now add a new Dynamics 365 FO project in the same solution and give the appropriate model.

Add a runnable class in the D365 FO as follows:


using AYDotNet;

class MCO_Test

{

    public static void main(Args _args)

    {

        var cal = new Calculator();

        Info(strFmt("%1",cal.Add(10, 20)));

    }

}


Now add the reference of the C# class in the D365 FO project as follows :



Now you will see something as below, select it and press Ok



Tada !!!