Tag Archives: D365

Date functions snippet in D365 Finance & Operations & Microsoft Dynamics AX

  • Get maximum date : TransDate maximumDate = dateMax();
  • Get minimum date: TransDate minimumDate= datenull();
  • Get Current or today’s Date: TransDate todayDate = today();
  • Convert string to date:  TransDate transdate = str2Date(’26-06-2020′, 123);(day = 1, month = 2, year = 3)
  • Convert date to string: str dateStr = date2Str(today(), 123, DateDay::Digits2, DateSeparator::Hyphen, DateMonth::Digits2, DateSeparator::Hyphen, DateYear::Digits4, 0);
  • Convert String to datetime: utcdatetime dateTime = str2Datetime(‘26.06.2020 11:00:00 pm’, 123);
  • Get current system date time : utcdatetime currentDateTime = DateTimeUtil::getSystemDateTime();
  • Get current system date : Transdate currentDate = DateTimeUtil::getSystemDate();
  • getCompanyTimeZone = DateTimeUtil::getCompanyTimeZone();
  • getUserPreferredTimeZone = DateTimeUtil::getUserPreferredTimeZone();
  • getClientMachineTimeZone = DateTimeUtil::getClientMachineTimeZone();// get clie
  • getOriginatingTimeZone = DateTimeUtil::getOriginatingTimeZone(transDateTime); // get originating time zone
  • dateTime = DateTimeUtil::minvalue(); // get minimum value of date time
  • dateTime = DateTimeUtil::maxvalue(); // get maximum value of date time

D365 FO/AX7: Sharepoint File Upload using X++

Requirement :

Uploading a file in Sharepoint online using X++ and inside from Microsoft Dynamics 365 finance and operations.

Prerequisites:

The current user id of Microsoft Dynamics 365 Finance and operations should have proper rights and privileged in Sharepoint Online.

Sample Code:

In this scenario i am creating a text file in Microsoft Dynamics 365 finance and operations and then uploading its memory Stream in Sharepoint online using X++ . You can modify the X++ code in D365 finance and operations as per your need.

class RunnableClassRun
{
/// /// Runs the class with the specified arguments. ///
/// The specified arguments.
public static void main(Args _args)
{
System.UriBuilder builder = new System.UriBuilder(“https://XXXXXX.sharepoint.com”);
str extId = xUserInfo::getExternalId();
Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider provider;
Microsoft.Dynamics.AX.Framework.FileManagement.DocumentLocation documentLocation = new Microsoft.Dynamics.AX.Framework.FileManagement.DocumentLocation();
provider = new Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider(“XXXXXX.sharepoint.com”, “sites/dummy”, “Shared%20Documents/MyFolder”, extId);
System.Byte[] reportBytes = new System.Byte[0]();
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
reportBytes = enc.GetBytes(“YOUR STRING/TEXT”);
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(reportBytes);
//memoryStream = comma.getStream();
documentLocation = provider.SaveFile(newGuid(), ‘TextFile.txt’, System.Web.MimeMapping::GetMimeMapping(‘TextFile.txt’), memoryStream);
}

}

}

D365 FO/AX7/Class Extension: COC (Chain of command) & Method Wrapping With Example

  • Introduction COC (chain of command) & Method Wrapping In Microsoft Dynamics 365 finance and operations –
  • Microsoft D365 Finance and operations supports very powerful feature called COC or method wrapping.
  • In past, Microsoft Dynamics AX/Axapta supports overlayering where you can overlayer Microsoft classes, table methods etc directly by placing your code in the middle, bottom or top if standard code. Below is screenshot and example for your reference. In below screenshot i placed my custom code in the middle of standard method by using overlayering.
  • In Microsoft Dynamics 365 finance and operations (After version 8.0) , you cannot overlayer code as everything is sealed now. We have to use COC or method wrapping.Microsoft has improved the Functionality of Class extension for D365 FO by adding wrap logic around methods which are defined in the base class that you are augmenting. You can Wrap or do Chain of command (COC) of public and protected methods.
  • In below screenshot i am using method wrapping or class extension of standard class which is different from Microsoft Dynamics AX overlayering approach.

  • Next keyword means to call the orginal method “ChecItemPostingDate” of standard class “InventUpdate”
  • You can get values of Global Variables of in your extension class of your parent class or main class.
  • Final Modifier means The method can’t be overridden in any class that derives from its class.
  • Here are one more example where we are using COC (chain of commands) in Table methods.

Benefits Of Using Change Of Commands instead of Old Overlayering approach in Microsoft Dynamics 365 finance and operations

  1. Easy Future upgrades and version enhancements as you are not doing overlayering in standard classes or methods or objects & keeping you separate extension classes.
  2. Neat & Clean development as no need to compile whole code librarary.

D365 FO/AX7: Merge Branches Or Moving Changes from One Branch To Another in VSTS/Azure DevOps

Requirement: In last post i demonstrated how can we create A New Production Branch In VSTS (Visual Studio Team Services)/Azure DevOps & Microsoft Dynamics 365 finance and operations. To See my last post please click here. In this post i will show how can we Merge Branches in VSTS/Azure DevOps and Microsoft Dynamics D365 finance and operations or how can we move change or CHANGESets from one dev branch to another prod branch. Before starting this tutorial i will recommend you to please go through my last post.To See my last post please click here

  • Right Click on SOURCE Branch & choose option MERGE
  • Browse TARGET Branch
  • You can choose 2 option for branch changes you would like to merge.First one is “ALL CHANGES UPTO SPECIFIC VERSION” & second one is “SELCTED CHANGESETS
  • Click NEXT and FINISH

D365 FO/AX7: Multithreading With Example Using Pessimistic LOCK & BatchHeader/BatchTask Class

Background – In Microsoft Dynamics D365 Finance and Operations, most of the processes & batch jobs run in a single thread and supports only single thread execution not multi-threading. Generally Single Thread batch Jobs or processes work well in Microsoft Dynamics 365 Fins and ops. But there are many scenarios where we require fast performance and quick competition of processes and batch jobs. Multithreading Batch Jobs approach is very useful in those scenarios.

Two Different Ways In Microsoft Dynamics D365 Finance and Operations,We can develop Multithreaded Batch Jobs in two ways. The first approach is using PESSIMISTIC LOCKS OR PESSIMISTIC SELECT in Microsoft Dynamics D365 Finance and Operations.

The second is to create BATCH TASKs. Batch Task approach you can find in standard classes like RetailStatementCalculate_Multi, RetailStatementPost_Multi Etc. which are using RunBaseBatch Framework (Not SYSOperation Framework) inside Microsoft Dynamics D365 Finance and Operations.

Lets begin with first approach i.e. using PESSIMISTIC LOCKS OR PESSIMISTIC SELECT in Microsoft Dynamics D365 Finance and Operations.By default, D365 fins and ops supports Optimistic Concurrency model (OCC) during the time SELECT or fetching records from database of Microsoft Dynamics D365 Finance and Operations. Optimistic Concurrency Model or SELECT only locks records during the time of Update whereas Pessimistic Concurrency Control (PCC).

Below code you can utilize in batch jobs and you run multiple thread of same batch job class as we a

Lets move to second approach , which include create and adding RUNTIME task using BATCHHEADER class . Here a single Runbase Batch Job is used for creating multiple threads or Runtime Tasks.

D365 Fins & Ops/AX7: Extend & Customize Retail Statement Posting|Part 1|D365 Commerce|D365 Retail

Retail Statement Posting– Retail Statement Posting or Day End Posting in Microsoft Dynamics 365 finance and operations/D365 Commerce/D365 Retail is very important process. In Dynamics 365 Commerce, Retail statement posting process is a batch task which updates financial Transaction, customer transactions & inventory transactions. Retail statement posting process consists automation of activities like creation of sales order from D365 MPOS/CPOS retail sales transactions, invoice posting of sales order , retail tender payments & customer settlements.

Scenarios– Extension & Customization of Retail posting routine is a common requirement and classes architecture & posting routines is way more different than Microsoft Ax 2012 retail statement posting and totally new.

Example 1 :

During the time of retail statement posting, developer wants to carry custom fields in SalesLine or wants to update value of fields in SalesLine.During Retail statement posting , RetailTransactionServiceOrder Class is resposible for creation of SalesTable or Customer Order. Fortunately, Microsoft provides a class RetailCreateCustomerOrderExtensions for extending Retail Statement posting – Customer Order Creation Process. You can extend the class RetailCreateCustomerOrderExtensions and by using Chain of command (COC) of method RetailCreateCustomerOrderExtensions.preSalesLineCreate() you can achieve mentioned scenario.

Example 2:

In example 1 we are modifying the value of SalesLine. In this example , developer wants to update or carry new fields in SalesTable or customer Order Header during Retail Statement Posting.You can extend the class RetailCreateCustomerOrderExtensions and by using Chain of command (COC) of method RetailCreateCustomerOrderExtensions.orderHeaderBeforeInsert() you can achieve mentioned scenario.

D365 FO/AX7: The natural key for the table XXXX was not found [Solved] Data Entity Error

  • Issue – During the creation of data entity of table VendInvoiceTrans in Microsoft Dynamics 365 Finance and operation, system is throwing error- The natural key for the table VendInvoiceTrans was not found.
  • Root Cause The reason is that the table VendInvoiceTrans is using  RecId as its primary index. D365 Fo Data Entity Wizard doesn’t support tables with a RecId as a primary index.
  • Steps to Solve
  • Duplicate any existing data entity in your D365 fins and ops project and model. In my case i am making a duplicate copy of existing data entity – EMPSurveyTableEntity
  • Rename the duplicate copy of data entity
  • Change the existing datasource of data entity from EMPSurveyTable to VendInvoiceTrans
  • Delete existing fields of data entity and add new field from datasource vendInvoiceTrans
  • Remove the field from KEYS –> ENTITY KEY and new fields as per your need from datasource VendInvoiceTrans. ENTITY KEY fields should not allow duplicate and should be unique combination.
  • Change the Data entity properties PUBLIC COLLECTION NAME , PUBLIC ENTITY NAME & DATA MANAGEMENT STAGING TABLE to new values.
  • Right click on data entity and regenerate Staging Table Again
  • Assign data entity to security privilege.
  • Rebuild and synchronize the project .

D365 FO & MS Forms Pro Survey Integration : Send & Save Survey Responses using Microsoft Power Automate/Microsoft Flow/Azure Logic Apps

  • Objective – Microsoft Dynamics 365 (Finance & operations) & Forms Pro Survey Integration : Send and Save Survey Responses using Microsoft Power Automate/Microsoft Flow/Azure Logic Apps.
  • Scenario – Organisation wants to send Employee Satisfaction Survey to their employees via email. Employee will complete the survey . Survey Responses should be store and save in Microsoft Dynamics 365 Finance & operations.
  • Technologies/Products – Microsoft Form Pro(Free 30 Days Trial), Microsoft Dynamics 365 Finance & operations, Microsoft Power Automate(Microsoft Flow/Azure Logic Apps).
  • Prerequisite – Before moving ahead individual must go and see my old post on Microsoft Forms i.e. Microsoft Forms : Create a Survey Form From Scratch. Individual should have knowledge of Microsoft Power Automate(Microsoft Flow/Azure Logic Apps) & Dynamics 365 Finance & operations development.
  • Send Survey – Login to Microsoft Power Automate/Microsoft Flow/Azure Logic Apps. Create a Microsoft Flow for sending Employee Surveys to the employees of the company . In this scenario i am using a custom data entity of Employee master which is returning fields – Employee Code & Employee Email, Employee. You can use your own data entity as per your requirement and business need. I am reading all the Employee records and sending surveys in their email. You can add more conditions as per your business need. For demonstration purpose i am keeping things simple.Please refer below flow for your reference.
  • Storing and saving Survey responses – Create a Microsoft Flow for Storing and saving Survey responses in Microsoft Dynamics 365 Finance and operations using D365 FO custom data entity and Microsoft Flow Fins and ops connectors.Please refer below flow for your reference.

Cheers, piyush adhikari +91-7995802472 & piyushadh@gmail.com

Microsoft Forms : Create a Survey Form From Scratch

Introduction

Microsoft Forms is online application & surveys creator tool which helps you to create surveys, quizzes & polls. Microsoft Forms also comes with Microsoft Forms Pro version with many more integration capabilities and features as comparison to basic version.With Microsoft Forms Pro, you can create and send surveys and receive survey responses in Dynamics 365 Applications along with other Dynamics 365 data. Microsoft Forms can be easily integrated and used with applications like Microsoft Flow, Microsoft Power Automate & Microsoft Azure Logic Apps.

Steps To Create a Survey From Scratch

  • Under My Forms, click on New Pro Survey
  • Input your survey title and its description.
  • Add new rating question.
  • Fill question and its description
  • In the end, your Microsoft Forms Preview Should look like this.
  • Click on Send to see sharing options
  • You can send Microsoft Forms via email or you can configure it in Microsoft Flow / Azure Power Automate or You can share Microsoft Forms Link or QR Code. There are so many options