Tuesday, August 22, 2023

Create access token from c sharp code and get it in dynamics 365 FO

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;

namespace AY_AccessToken
{
    public class ClassAccessToken
    {
        private static string clientId = "2539b54-0891-4aad-99a6";
        private static string clientSecret = "H18Q~DntOA9aQX";
        private static string resource = "https://10devadevaos.axcloud.dynamics.com";
        private static HttpClient httpClient = new HttpClient();

        public static string GetAccessToken()
        {
            var content = new StringContent($"grant_type=client_credentials&client_id={clientId}&client_secret={clientSecret}&resource={resource}");
            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");
            var response = httpClient.PostAsync("https://login.microsoftonline.com/bacbd475-b9da-43fa/oauth2/token", content).GetAwaiter().GetResult();
            var result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            string accessToken = result.Split(':')[1].Split(',')[0].Replace("\"", "");


            string search = "\"access_token\":\"";
            int start = result.IndexOf(search) + search.Length;
            int end = result.IndexOf("\"", start);
            string accessTokenFinal = result.Substring(start, end - start);
            return accessTokenFinal;
        }
    }
}


Dynamics 365 F&O code to get the token:

using AY_AccessToken;
internal final class RunnableClass1
{
    public static void main(Args _args)
    {
        str accessToken;
        accessToken = ClassAccessToken::GetAccessToken();
        info(accessToken);
    }
}

Friday, August 11, 2023

Aggregate dimensions and aggregate measurements in Dynamics 365 FO

Aggregate dimensions and aggregate measurements in Dynamics 365 Finance and Operations (F&O) are components used within reporting and analytics.


Aggregate Dimensions: These are attributes or characteristics that allow data to be categorized and grouped. They are typically used to filter or slice data within reports. For example, an aggregate dimension might be a product category, region, or salesperson. By using these dimensions, you can summarize and analyze data in a way that makes sense for your organization.


Aggregate Measurements: These refer to the actual data values that are being summarized and analyzed. Aggregate measurements include things like total sales, quantity sold, or profit margins. They are typically used in conjunction with aggregate dimensions to provide a comprehensive view of the data. Aggregate measurements can be viewed in various summaries such as sums, averages, counts, etc.


In Dynamics 365 F&O, both components play an essential role in creating powerful and insightful reports. Aggregate dimensions provide the framework for viewing data, while aggregate measurements provide the actual content being analyzed. Together, they enable users to tailor reports and analytics to meet specific business needs and objectives.



Youtube video : Link

Entity store : Link

BYOD : Link

CloudFronts : Link

Efficient Data Reporting and Analysis : Link

Wednesday, August 9, 2023

Enqueue and Dequeue in Dynamics 365 FO

Enqueue:

Sending data from another system to Dynamics 365 F&O. When data needs to be transferred to Dynamics 365 F&O, it's placed into a queue (enqueued), awaiting processing within the Dynamics system.


Dequeue:

Sending data from Dynamics 365 F&O to another system. After the data has been processed within Dynamics 365 F&O, it can be removed from the queue (dequeued) and sent to another system as needed.


So in summary:

Enqueue is related to receiving data into Dynamics 365 F&O.

Dequeue is related to sending data from Dynamics 365 F&O to another system.

Link to understand Enqueue and Dequeue

Tuesday, August 8, 2023

How to create a logic app in azure to move files in SFP from one folder to another

Go to Azure portal : Azure

You will see window like below


Click on "Create a resource"


A new window will open, there search for "Logic apps", as shown below


Now new window will come like below, select create > Logic App


Now new window will come like below


Enter the resource group, logic app name, select the region, select the plan type as consumption

Now click next > Next, you will see a window like below


Click on create

Deployment will take some time, now go to the resource
The moment you will go to resource, Logic app designer will be opened automatically like below


Go downwards and click on 'Blank logic app'


Logic app designer will open like below



Search for appropriate triggers, in my case I will be searching for "Recurrence"
Select the icon shown below


after that select Recurrence again as shown below


New window will open like below


Set in the parameters acc to your need, I will be setting Once a day
Now click on Next step, a window will open like below, where you can select actions


Now select variables, and select in "Initialize variable" like below


Now fill in the name of the variable and type like shown below


Now you may rename the action as well, as shown below


Now do the same for "To path" variable as shown below


Now add an action and 'SFTP' and select 'List files in folder', as shown below


you will see something like below


In my case I have already setup the SFP connection, but you can also setup like below


Fill in the connection name, host server address, username and password (click on disable SSH host key validation) if you are using username and password

Now save the connection and make it as default

Now click on the Folder, a lookup will come like below


Selected 'From path' from the variables, final should look like below


Now click on, New step and  search for 'For each' in control


Now select the 'body', as shown below


Rename the 'For each' to 'Move to each file' and Now the logic app should look like below



Now select an action inside the loop, now search for condition and select like shown below


Now condition action will be added, there you can select Name in the condition as shown below


expression should look like below


Now in the true side, search for SFTP and select "Copy file" as shown below


Now the copy file action should look like below


the 1st expression in the Destination file path is utcNow('yyyy')
and the 2nd expression in the Destination file path is utcNow('MM')

Now below that action add an action 'Delete file' as shown below


Now configure the Delete file action like below


Tada!!!