Monday 31 August 2020

Convert JSON to Object using C# Code

Hi Everyone,

Many times we get a requirement to convert JSON string to C# Object and most of the times, we go with Newtonsoft Dll. In Dynamics 365 Plugins, we all know it is not recommended to use Newtonsoft as we have to use ILMerge to merge the dlls and deploy.

Here is the easy way to convert JSON string to C# object without using external references.

You have to add below references from .net framework to your project.

using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.IO;

        [DataContract]
        public class MyClass
        {  
            [DataMember]
            public string Firstname { get; set; }
            [DataMember]
            public string Lastname { get; set; }
        }

        static void Main(string[] args)
        {
            // string strJSONstring = Console.ReadLine();
            string strJSON = "{\"Firstname\":\"Dynamics 365\", \"Lastname\":\"Customer Engagement\"}";
            MyClass objMyClass = null;
            using (var stream = new MemoryStream(Encoding.Unicode.GetBytes(strJSON)))
            {
                DataContractJsonSerializer deSerializer = new DataContractJsonSerializer(typeof(MyClass));
                objMyClass = (MyClass)deSerializer.ReadObject(stream);
            }
        }

Hope this helps.

--
Happy Coding
Gopinath.

Sunday 30 August 2020

Find the current opened file in the solution explorer - Visual Studio tips

Hi Everyone,

Today I was working on some project and I have added a new file in the project, we have a habit of refreshing Solution Explorer when we do this. 

Instead of clicking on Refresh button on Solution Explorer, it happened to click the button which is next to it. Trust me, I have never used and don't even know anything about that till I clicked it.

I feel, it is a good feature that every developer must know. When we click on this, it automatically selects the file which is currently opened in Canvas. Check the below video to understand more.


This has raised a thought in my mind, why don't Visual studio automatically select the item which is opened instead of giving a button to click. After a quick search on this came to know that there is setting for this.

Visual Studio  --> Tools  --> Options  --> Projects and Solutions  --> General
Check "Track Active Item in Solution Explorer" which will automatically selects the current opened file in Solution Explorer.

Hope this helps.

--
Happy Coding,
Gopinath.

Programmatically Recalculating Rollup fields using C# in Dynamics 365/CRM

Hi Everyone,

Today I got an requirement to send some data to external system and they were looking for real time data. When I did the fields found some Rollup fields and we all know that Rollup fields are asynchronous in nature and it is managed by Recurring System Jobs.

I was kind of stuck, did a little search and understood that there is a SDK message which we can use for recalculating. Here is the code for the same.


CalculateRollupFieldRequest rollupRequest = new CalculateRollupFieldRequest
            {
                Target = new EntityReference("account", new Guid("475b158c-541c-e511-80d3-3863bb347ba8")),
                FieldName = "new_rollupfromchild"
            };


CalculateRollupFieldResponse response = CalculateRollupFieldResponse)crmService.Execute(rollupRequest);

Hope this helps.

--
Happy 365'ing
Gopinath.

#Error on Preview - SSRS Report new field

Hi Everyone,

Today I was working on the report and the requirement was to add one more field in the existing table and show it. I have modified the data source accordingly and mapped the field in the table of SSRS report. When I tried to preview the same, it was showing the value as #Error.

I was little surprised and checked the mapping and data source. Everything seems to be correct and somehow the report is not showing the fields value in preview mode. 

After some search came to know that it seems to a bug/by design in SSRS. For every report, you will see a .data file in your report project and it is basically caching the data. Just deleting that file and running the report again fixed the issue.

You can also just do refresh in the preview by the clicking on the button highlighted below.

Hope this helps.

--
Happy Reporting
Gopinath

List Records Output not showing in Power Automate/Microsoft Flow

Hi Everyone,

Today I have configured a CDS List Records step in flow to retrieve some records and I have to parse them and do some operation. We all know that for Parse JSON step, we have to give schema. In these type of cases, usually we run the flow first till List Records step and copy the output from that step and give copied output to generate schema in Parse JSON step.

When I was doing the same, unfortunately the list records steps is not showing output and not giving any option to download the result as well. I was kind of stuck with that and by doing quick search came to know that we can Compose Step  give the output the List Records step to Compose step so that we can see the result and use it for generating schema.


Hope this helps

--
Happy 365'ing
Gopinath

Get a single/first record from CDS/Dynamics 365 List Records action step in Power Automate/Microsoft Flow


Hi Everyone,

Today I was working on Microsoft Flow and I have List Records step configured in the flow. As per the requirement, I know that the result of the List Records step would be one record or empty. We all know that to get the data from List Record, normally go with Apply to each step as I already know that the output count of records would not be more than 1 taken below approach.

List Records Step  -->  Take the required values using First function.

first(body('List_records')?['value'])?['accountid']

This returns empty string if the count is 0 else the value.


Hope this helps

--
Happy 365'ing
Gopinath

Saturday 15 August 2020

Open the required App in much more easier and faster - Dynamics 365 CE 2020 Release Wave 2

Hi Everyone,

Today I was exploring the latest features on the Dynamics 365 CE 2020 Release Wave 2 and I have opened Sales Hub, after sometime I would like to open Customer Service Hub and to my surprise I was not able to find the Icon (check the below screenshot) that used to show the Apps in the system.

After some search, it was replaced with the Hyperlink on the App Names itself.



Hope this helps.

--
Happy 365'ing
Gopinath.

Friday 14 August 2020

Get InitialValue of a field in JavaScript - in Dynamics 365 CE

Hi Everyone,

Today I was going through Client API from Microsoft Docs and found getInitialValue reference. I haven't used it anytime and explored little bit. 

Many times we get the requirement to compare the field values on the Save with the values that were populated on the load and to achieve this, normally we use declare a global variable in JavaScript and set the variable to the value of the field on the Load event and use it on Save for comparing. We can say good bye to these kind of logics and use getInitialValue() to get the value when the form is opened.

Here is the syntax for the same.

formContext.getAttribute(<attributename>).getInitialValue()

Note: 
1) This method works for only Boolean, OptionSet or MultiSelectOptionSet attributes. 
2) Once the record is saved, getInitialValue holds the latest value whatever that was changed by the user.

Hope this helps.

--
Happy 365'ing
Gopinath.

Thursday 6 August 2020

Get Security Roles of logged-in/current user in JavaScript - Dynamics 365 CE

Hi Everyone,

Let's say bye bye to all the code that we used to write for getting Security Roles of the logged in User. 

Here is the single line of the JavaScript code which gets all the Security Roles GUIDs along with names.

Xrm.Utility.getGlobalContext().userSettings.roles.getAll();

Security roles associated with the user.

Security roles associated with the Team where user is a part of the Team.


When we run the code, here is the output.


Hope this helps.

--
Happy 365'ing
Gopinath.

Wednesday 5 August 2020

Enable 2020 Release Wave 2 – Dynamics 365

Hi Everyone,

Release Wave 2 Early access has been released and here are the steps to enable it on your instance

Logon to Admin Portal

Open the environment which you would like to enable Early access and click on Manage.

You will see the screen as below and click on Update now for getting Release Wave 2 Features to the instance.

You will be asked to enter Environment's name for the verification.

After verification, the Update process starts and it will take some time.

Hope this helps.

--
Happy 365'ing
Gopinath.

Monday 3 August 2020

Microsoft Dataflex, Microsoft Dataflex Pro versus Common Data Service

Hi Everyone,

Would like to put this post simple and short. We all know the recent announcements from Microsoft on Dataflex. I was talking to one of my friends things were not much clear.

There are only two things to understand

1) Microsoft Dataflex Pro  -  Common Data Service would be renamed to Microsoft Dataflex Pro.
2) Microsoft Dataflex  -  a low-code data platform for Teams which is build on top of Common Data Service (Microsoft Dataflex Pro as per point 1).

Read more from here

I am sure this will have a ripple effect on multiple things but for now we have to wait for more announcements to come.

--
Happy 365'ing
Gopinath