Monday, October 25, 2021

How to restrict future date in MS CRM 365

Recently our client has came with the requirement that, they don’t want to allow a future date selection for a particular field on Microsoft Dynamics CRM form.

Well, it is not a complex task to implement. Here is the sample code for it-

function restrictFutureDate() {

    if (Xrm.Page.getControl("Date_Field")) {
        var getfieldValue = Xrm.Page.getAttribute("Date_Field").getValue();
   
        var today = new Date();
   
        if (getfieldValue > today) {
   
            Xrm.Page.getControl("Date_Field").setNotification("Future date is not allowed!", "DATEERROR");
        } else {
   
            Xrm.Page.getControl("Date_Field").clearNotification("DATEERROR");
        }

    }
}

Saturday, October 23, 2021

Set Lookup Value in MS CRM 365 using JavaScript

 

While working on client-side customization using Java Script in MS CRM 365, it is very common requirement to set the Lookup field value which can be done using following code-

Here is the sample function which can be use to set the Lookup filed value-

function setLookupField(executionContext,fieldName, recordId,
recordName, entitySchemaName) {
    var formContext = executionContext.getFormContext();
    var lookupData = new Array();
    var lookupItem = new Object();
    lookupItem.id = recordId;
    lookupItem.name = recordName;
    lookupItem.entityType = entitySchemaName;
    lookupData[0] = lookupItem;
formContext.data.entity.attributes.get("parentcontactid").setValue(lookupData);

}

 

The code demonstrate itself that it is not enough to set the record id to the field, it is necessary to set record id, name and entityType then the value will reflect correctly in the field which is placed on the form.

 

Hope this will help.

Get Lookup Value in MS CRM 365 using JavaScript

 

While working on client-side customization using Java Script in MS CRM 365, it is very common requirement to get the Lookup field value which can be done using following code-

Let’s look into the code step by step-

First of all we have to get the entity object using formContext.data.entity.attributes.get() Method

E.g.

var ObjAccount = formContext.data.entity.attributes.get("accountid");  

 

Once the object is available in the variable ObjAccount we can use GetValue() method as shown below-

E.g.

var ObjAccountValues = ObjAccount.getValue();

 

GetValue() Metho return the id, name and entityType properties which can we accessed as shown in full function written to get the Looup Values

function LookupValueFctn(executionContext) {
    var formContext = executionContext.getFormContext();
var ObjAccount=formContext.data.entity.attributes.get("accountid");  

    if (ObjAccount != null) {
        var ObjAccountValues = ObjAccount.getValue();

        if (ObjAccountValues != null) {
            var Accountid = ObjAccountValues[0].id;  
            var AccountNameName = ObjAccountValues[0].name;
            var EntitySchemaName =ObjAccountValues[0].entityType;
        }
    }
}

 

Tuesday, October 12, 2021

How to pass execution context from Ribbon Workbench in MS CRM 365

As Microsoft has deprecated Xrm.Page, we have recently required to correct our JavaScript code where we use Xrm.page.

For example we have used Xrm.page.data.save method multiple places in our JavaScript customization code, which we have to replace with formContext.data.save. The JavaScript functions which are getting called from the form or field event it is easy to pass the execution context.

In case of the functions which are getting called on click of Ribbon button is explicitly requires to pass the CRM parameter using Ribbon Workbench customization, below are the steps which needs to follow the same-

 

1.     Load the solution in Ribbon Workbench

2.     Choose to modify the Command for this custom Name button and click on Add Parameter


3.     After selecting the Add Parameter, select CRM Parameter:


 

4.     Select Primary Control from the dropdown


 

Now you can get formContext from this parameter as easily as if it were the executionContext.

Here is code example if you are calling function on lick on Form Ribbon button

function ribbonButtonClick(executionContext)

{

       executionContext.data.save();

}

 


Monday, October 11, 2021

Retrieve Record Using XRM.WebAPI

In Dynamics 365 version it is very easy to retrieve the entity record in JavaScript is quite simple and not requires writing multiple lines of code.

On success it returns a promise containing a JSON object with the retrieved columns and their values.

Here a basic retrieve example-

Retrieves the name and revenue of an account record with record ID = 5531d753-95af-e711-a94e-000d3a11e605.

Xrm.WebApi.retrieveRecord("account", "a8a19cdd-88df-e311-b8e5-6c3be5a8b200", "?$select=name,revenue").then(

    function success(result) {

        console.log("Retrieved values: Name: " + result.name + ", Revenue: " + result.revenue);

        // perform operations on record retrieval

    },

    function (error) {

        console.log(error.message);

        // handle error conditions

    }

);

The above example displays the following in your console; you might see other values depending on your data:

Retrieved values: Name: Sample Account, Revenue: 5000000


Reference:

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/retrieverecord


Wednesday, October 6, 2021

Tooltip for label in not showing after upgrading to release 2021 Wave 2

We have recently applied Release 2021 Wave 2 to our MS CRM 365 instances and found that it is not showing Tooltip for the labels which we configured, isnt it strange behaviour?

Tried to find out reasong behing it and found that Microsoft has deprecated the Tooltip feature in this release with below description provided by Microsoft-


Tooltips for column descriptions on model-driven forms

With the upcoming 2021 release wave 2 (public preview in August 2021 and GA in October 2021), hover tooltips on column labels for full descriptions will be removed.

Why is this needed?

  • These tooltips aren't an accessible way to access information about the column.

Impact

  • Starting October 2021, these descriptions will no longer be available on hover.
  • We will be introducing a new fully accessible feature for April 2022.

Hope this will help.

Reference-
https://docs.microsoft.com/en-us/power-platform/important-changes-coming

Tuesday, October 5, 2021

Connector in Power Automate

 There are 3 ways to deploy Power Automate flows-

       1.       Can be done using exporting it using package

2.       To Adding it in Solution and Exporting the solution and importing it in target organization

3.       Addition the flow in solution and creating Connection Reference in the solution.

 

If we go with first two options we have to update the connection settings in every flow as well in all the steps where the connection reference is, so better approach is to use the connection reference.

 

Here are the steps which I have followed to create flow with reference to Connection Reference.

 

1.       Created a new solution in Dev7- PowerAutomateConnection

2.       Using add new Item option added new Connection Reference with below shown details in screenshot-

 



 

3.       Now created New Test flow in this solution which has took automatically reference of the Connection Reference which I have created, please refer below screenshot.

 






 

4.       Once the flow is tested exported the solution as managed solution.

5.       Login to UAT2 power automateà got o Solution and click on Import.

6.       After selecting the managed solution import and click next it ask to update the connection, if there is not any existing Dataverse connection created, click on New Connection and create the new Dataverse Connection.

 



 

7.       Once the creation has been created click on the refresh button the new connection will appear in the drop down, select it and click on import as shown in following screenshot.

 



8.       That’s it once the solution has been imported you don’t need to do update any connection reference in flow and its steps.

9.       Now the flows are ready to execute.

Monday, October 4, 2021

Customize Rich Text Edit in MS CRM 365

Microsoft has introduced the Rich Text Editor Control in Recent version which is very useful and powerful text editor which we can use on the form. I have recently implemented and customize it as per the client requirement, please check below details for it.

 

As client wanted to format the text on the form which is get fulfilled using the Rich Text Edit control and when we use the Rich Text Edit Control it get render with the default formatting Toolbox as shown in below image.

 

 

Now the problem is client wanted to customize the Toolbox of the Rich Text Edit control e.g. in our case client don’t wanted change the Font and Font Size to the user and that’s why asked me to remove Font and Font size from the Rich Text Editor Toolbar.

 

Well, I have tried to find out is there any setting in control properties in a form designer but there is no such kind of settings available for the control.

 

After checking the documentation provided my Microsoft for the Rich Text Editor Control I found that it can be done using RTEGlobalConfiguration.json web resource, this web resource contains all configuration settings for the Rich Text Box Edit Control.

 

As per our requirement I have remove the Font and Font Size Option from the toolbox property in this web resource.

"toolbar": [

      [ "CopyFormatting" ],

      [ "Bold" ],

      [ "Italic" ],

      [ "Underline" ],

      [ "BGColor" ],

      [ "TextColor" ],

      [ "BulletedList" ],

      [ "NumberedList" ],

      [ "Outdent" ],

      [ "Indent" ],

      [ "Blockquote" ],

      [ "JustifyLeft" ],

      [ "JustifyCenter" ],

      [ "JustifyRight" ],

      [ "Link" ],

      [ "Unlink" ],

      [ "Subscript" ],

      [ "Superscript" ],

      [ "Strike" ],

      [ "Image" ],

      [ "BidiLtr" ],

      [ "BidiRtl" ],

      [ "Undo" ],

      [ "Redo" ],

      [ "RemoveFormat" ],

      [ "Table" ]

    ]

 

Once it is done save the web resource and publish, that’s it now if you check the Rich Edit Control on form it will render without Font and Font Size tools in toolbar.

 

 

For more details please refer-

 

https://docs.microsoft.com/en-us/powerapps/maker/model-driven-apps/rich-text-editor-control#use-the-webresource-for-organization-wide-changes

 

QueryExpression vs. FetchXML in MS CRM with C#

Microsoft Dynamics CRM (Customer Relationship Management) is a powerful platform that helps organizations streamline their business processe...