Tuesday 29 September 2020

Sign in required popup - Make.PowerApps.com

 Hi Everyone,

Today, I was trying to logic to Make.PowerApps.com and I was getting a popup as below. The reason could be, if you have logged on with two or more user accounts to different Dynamics 365 systems, you might get this issue. 

Clearing browser cache helped me to get rid of the issue.

Hope this helps.

--
Happy 365'ing
Gopinath.

Monday 28 September 2020

Get User Privilege on a field - Dynamics 365 CE

 Hi Everyone,

Today I got a requirement to check whether the user has access to read the data on the field where field level security has been enabled and do some operations.

We can achieve this using getUserPrivilege() client API.

var fieldPrivileges = formContext.getAttribute("new_fieldsecurityfield").getUserPrivilege();

Result when user doesn't have permission.

Result when user have permission.

Hope this helps.

--
Happy 365'ing
Gopinath.

Download Plugin Registration Tool using PowerShell - Dynamics 365 CE

Hi Everyone,

Here are the steps to download Dynamics 365 CE Plugin Registration Tool via PowerShell.

1) Type Windows Powershell in windows start menu and open it.
2) Navigate to the folder where you would like download the tool.

3) Copy and paste the following PowerShell script into the PowerShell window and press Enter.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = ".\nuget.exe"
Remove-Item .\Tools -Force -Recurse -ErrorAction Ignore
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
Set-Alias nuget $targetNugetExe -Scope Global -Verbose
 
##
##Download Plugin Registration Tool
##
./nuget install Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool -O .\Tools
md .\Tools\PluginRegistration
$prtFolder = Get-ChildItem ./Tools | Where-Object {$_.Name -match 'Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool.'}
move .\Tools\$prtFolder\tools\*.* .\Tools\PluginRegistration
Remove-Item .\Tools\$prtFolder -Force -Recurse

4) You will see the Tool at the given path.

Hope this helps.

--
Happy 365'ing
Gopinath.

Sunday 27 September 2020

Get Api Version in JavaScript for WebApi Requests - Dynamics 365 CE

Hi Everyone,

Today I was reviewing the code that was written an year ago and in most of the places I have seen the code like below.

req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/accounts(3851da21-5ae9-ea11-a817-000d3a5308e0)?$select=accountid,accountnumber,name", true);

If you observe that Version has been hard corded in the request, even though it works perfectly I would say, we can do the same in much more better way by taking  it dynamically.

Here is the way for the same.

    var apiVersion = Xrm.Utility.getGlobalContext().getVersion();
    console.log("API Version :  " + apiVersion);
    var version = apiVersion.substring(3, apiVersion.indexOf(".") - 1);
    console.log("Version : " + version);
 
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v" + version + "/accounts(3851da21-5ae9-ea11-a817-000d3a5308e0)?$select=accountid,accountnumber,name", true);

Hope this helps.
--
Happy 365'ing
Gopinath. 

Object reference not set to an instance of an object – error in Dynamics 365 Plugin Registration Tool

Hi Everyone,

Today I was working on some plugin work  and was On-Premise system and when I try click on Register new assembly via Plugin Registration Tool, I was getting "Object reference not set to an instance of an object" error.

If it was my machine, I could have downloaded XRMToolBox or latest Plugin Registration tool but I was working on the server and don't have any permissions to download the required. I was completely stuck with it and don't even know what to do. 

After quick search, came to know that clearing contents in Appdata would solve the issue.

Navigated to "C:\Users\<UserName>\AppData\Roaming\Microsoft\PluginRegistration" and deleted all the contents and then Plugin Registration started working normally.

Hope this helps.

--
Happy 365'ing
Gopinath.

Friday 25 September 2020

Configure Model Driven App Access to the Users - Dynamics 365 CE

 Hi Everyone,

In this post, we will go through the steps that are required for the users to get Access on the required apps.

Many times we get requirement to create a new Model-Driven App and when it is created System Administrator and Customizer have access on the app by default. For the other users, we have to give right access to get the App.

The first thing that is needed to get App access is Read Privilege on Model Driven App under Customization tab of the Security Role.

Next thing, you need to give the permission on App. This Apps specific, if there are 10 Apps in the system, we might want to give permission to only 2 App to the User. 

For this, Navigate to Settings -->Application --> Apps

Select the App which you wanted to give permission and click on ellipse (...) --> Manage Roles.

Select the roles for which you would like to give access and Save.

Hope this helps.

--
Happy 365'ing
Gopinath.

Customer Service Workspace App - Dynamics 365 CE 2020 Wave 2 Release

Hi Everyone,

Today I was exploring new features that were released in 2020 Release Wave 2 and found a new App named as Customer Service Workspace has been released.

This seems to be a game changer for Service Agents which gives Multiple Tabs and Session on UCI App itself.

Make sure you enable 2020 Release Wave 2 of Dynamics 365 CE to get this App.

Click on + button to open the Tabs

Click on any link (Record link, New Email, New Task etc.. ) by pressing Shift on keyboard to open a new session

By default we can have maximum of 10 Tabs and 9 Sessions in the current app. Couldn't find any configuration to change, please share it if you find it anywhere.

There are new forms added on Account, Contact and Case for multi session experience. 

Hope this helps.

--
Happy 365'ing
Gopinath

Thursday 24 September 2020

Hide Formselector on the Form - Dynamics 365 CE/CRM

 Hi Everyone,

Today I got a requirement to hide FormSelector on the Form as Users would have access to multiple forms but we have to navigate them to right form based on a field value on the record and we shouldn't give an option to change the form to the User. 

My initial thought was it's not possible to hide formselector but one of my colleagues came up with the below piece of the code and it worked like a charm.

Logic is simple, set Visibility of the forms to False.

 var formContext = executionContext.getFormContext();
    formContext.ui.formSelector.items.get().forEach(function (item, index) {
        // hide all the form apart from Opportunity.
        if (item.getLabel() != "Opportunity") {
            item.setVisible(false);
        }
    });

Without above code, we see formselector

With code, we don't see formselector.

Hope this helps.

--
Happy 365'ing
Gopinath

Retrieve Optionset Metadata using JavaScript - Dynamics 365 CE/Microsoft Dynamics CRM

Hi Everyone,

Today I got a requirement to retrieve Optionset Metadata using JavaScript.

Here is the code for the same.

function getOptionSetMetadata(schemaName) {
    var schemaName = "industrycode"; // You can pass this as a parameter to this function and comment this line.
     var optionSetFetch = `<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
        <entity name='stringmap' >
            <attribute name='attributevalue' />
            <attribute name='value' />
            <filter type='and' >
                <condition attribute='attributename' operator='eq' value= '${schemaName}' />
            </filter>
        </entity>
    </fetch>`;
    optionSetFetch = "?fetchXml=" + encodeURIComponent(optionSetFetch);
 
    Xrm.WebApi.retrieveMultipleRecords("stringmap", optionSetFetch).then(
        function success(result) {
            if (result.entities.length > 0) {
                console.log(result.entities);
                for (count = 0; count < result.entities.length; count++) {
                    console.log("Attribute Value : " + result.entities[count].attributevalue);
                    console.log("Value : " + result.entities[count].value);
                }
            }
        },
        function (error) {
            console.log(error.message);
        });
}

Here is the output.

Hope this helps.

--
Happy 365'ing
Gopinath.

Tuesday 22 September 2020

Where is Breadcrumb navigation in Dynamics 365 CE - 2020 Release Wave 2?

Hi Everyone,

Today I have updated my trail instance to 2020 Release Wave 2 and navigating here and there to understand the changes. I was so used to click on Breadcrumb in the top navigation as shown below and I couldn't see the same after enabling 2020 Release Wave 2. 

Yes, that's right. Breadcrumb navigation is gone now and there is a new button added on the Ribbon.

Hope this helps.

--
Happy 365'ing
Gopinath.

Timeline Control Features in Dynamics 365 CE - 2020 Wave 2 Release

Hi Everyone, 

Today I was going through the new features of Dynamics 365 CE 2020 Wave 2 Release and it seems we have good improvements on Timeline Control.

  • Expand the timeline records by default. 
  • Hide “What you’ve missed.” 
  • Show email as Conversation or as individual messages. 
  • Hide status.

Expand the timeline records by default  - This would give visibility of full content by default. This can be done by default by changing the Timeline Configuration on the Form.

Hide "What you've missed"  - Dynamics 365 will record the time you last accessed the record.  A new summary (filter) allows you to see the recorded Activities/Posts/Notes since that date and time. The setting is disabled by default. When enabled, a notification is displayed as shown in the below screenshot.

Show email as Conversation or as individual messages  - This is an option on the Timeline itself to show emails as full conversations or individual messages.

Show/Hide status  - We can show/hide status of the Activities on Timeline Control and this setting is maintained at Entity level on Timeline. 

Hope this helps.

--
Happy 365'ing
Gopinath.

Monday 21 September 2020

Advanced Find Icon missing - Dynamics 365 UCI Online

Hi Everyone,

Today I was working on Dynamics 365 CE UCI online version and noticed that Advanced Find button is missing. 

I am sure that we don't have any control on those button via Custom code or configurations. Thought of raising a support ticket with Microsoft and before doing that, did a quick search and came to know that someone has disabled the setting in System Settings.

I don't even know that there is a setting for this :)

Advanced Settings --> Administration --> System Settings --> General Tab --> Enable embedding of certain legacy dialogs in Unified Interface browser client  --> Change the setting to Yes

By default, the setting "Enable embedding of certain legacy dialogs in Unified Interface browser client" is set to Yes.

The button is back after changing the setting to Yes.
Hope this helps.

--
Happy 365'ing
Gopinath.

Saturday 19 September 2020

Microsoft.Crm.CrmException: Webresource content size is too big

Hi Everyone,

Today, I have received an error saying "Webresource content is too big" when I was importing PCF solution to one of our instances.

The fix is simple, the solution size which I was importing was more than 5 MB and the max file size limit for attachments was 5,120 (5 MB) in the instance. Updating the value to 10 MB (10,240) fixed the issue.

Settings --> Administration -->System Settings--> Email tab
Hope this helps.

--
Happy 365'ing
Gopinath.

Calculate the Age from Date of Birth in JavaScript

Hi Everyone,

Today I have got an requirement to calculate the Age based on Date of Birth.

Here is the way to get the Age using JavaScript.

function getAge(dateString) {
    // var dateString = '12/02/1988'
    var today = new Date();
    var birthDate = new Date(dateString);
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    console.log(today.getMonth())
    console.log(birthDate.getMonth())
    console.log(m);
    // Logically we cannot include the current year if the birthday has not completed in the current year.
    // The below condition checks the same and removes the current year from Age.
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
        age--;
    }
    return age;

}

Hope this helps.

--
Happy Coding
Gopinath.

Friday 18 September 2020

Convert C# Object to JSON string

Hi Everyone,

Check this post for Convert JSON object to C# Object.

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

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

        static void Main(string[] args)
        {
            MyClass myClass = new MyClass();
            myClass.Firstname = "Dynamcis 365";
            myClass.Lastname = "Customer Engagement";

            var memoryStream = new MemoryStream();
            var serializer = new DataContractJsonSerializer(typeof(MyClass));
            serializer.WriteObject(memoryStream, myClass);
            memoryStream.Position = 0;
            StreamReader streamReader = new StreamReader(memoryStream);
            string objectInJSONString = streamReader.ReadToEnd();

            Console.Write(objectInJSONString);
            Console.Read();

        }

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

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

Hope this helps.

--
Happy Coding
Gopinath

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.