Saturday, August 23, 2025

Hide And Show The Dynamics 365 CRM Button Based On Logged In User Security Roles

 In this post I am going to explain how you will hide and show the Ribbon/Command buttons based on logged in user security rule.

I have one Delete button on one Custom entity(Employee). I have to hide this button based on logged in user security roles, for it I used the Enable Rule.

Create the java script with function as below.

function HideLeadQualifyButtonBasedOnRoles()
{
    let hasRole = false;
    let roles = Xrm.Utility.getGlobalContext().userSettings.roles;
    roles.forEach(x =>
  {
        if (x.name === "Area Manager" || x.name === "Sales Manager")
{
            hasRole = true;
            return;
        }
    });
    if (hasRole === true) {
        return true;
    } else {
        return false;
    }
}



1. Open your solution into your ribbon workbench => Select your button => click on Enable Rule => Add Step


2. Select the CustomRule and add the Function Name and Web Resource.


3. Publish your changes.


What Is Display Rule And Enable Rule In RibbonWorkbench Of Dynamics 365 CRM/CE

In this post we are going to explain what is display rule and enable into Dynamics 365 CRM RibbonWorkBench.

The Display Rule and Enable Rule are used to perform the operation into Command or Ribbon buttons.

1. Display Rule:

This Display Rule are used to hide and show the ribbon button based on FormState Rule(create, existing, read only etc.), Value Rule, Option Set Rule etc.

=> Open RibbonWorkBench tool from your XrmToolBox or Solution Ribbon.
=> Open your solution into ribbonworkbench
=> select your button
=> Click on Display Rule + icon
=> Add new Display Rule
=> Click on Add Step
=> Now you will see the below options.



2. Enable Rule:

This Enable Rule are used to hide and show the ribbon button based on FormState Rule(create, existing, read only etc.), Value Rule etc. 
You can see you have the Custom Rule option into Enable Rule, by using you can run your own rules logic.

=> Open RibbonWorkBench tool from your XrmToolBox or Solution Ribbon.
=> Open your solution into ribbonworkbench
=> select your button
=> Click on Enable Rule + icon
=> Add new Enable Rule
=> Click on Add Step
=> Now you will see the below options.



Dynamics 365 CRM/CE Command Button/Ribbon Button Customizations

In this post we are going to explain to you how to work with Dynamics 365 CRM/CE Command/Ribbon button. Sometimes you will get the requirements to Add new button on Form, Tab and Subgrid.

Following are the some scenarios where you can use this.

1. Add or Remove button on Form, Grid and Sub-grid.
2. Hide and Show the buttons.
3. Customize the existing button functionality. etc

There are two ways to work on these Command/Ribbon button.

1. Power Apps
2. RibbonWorBench


1. Power Apps: 

1.1. Go to make.powerapps.com => Apps => Select your App (in which app you want to perform the operation) => Click on 3 dot => Edit => Edit in new tab.

1.2. Now select your Entity/Table View (Here I am using Account Entity/Table) => Edit command bar => Edit in new tab => 
1.3. Select the area where you want to customize operation. Here I am going to perform operation on Form.
1.4. Click on New to add the Button and Command. Once you add the right side you can give the name and library function.


2. Ribbon Work Bench:
2.1. To work with Ribbon WorkBench you have to create the Solution and add the only Entity/Table without any components. Here We created the solution with name RibbonCustomization and added the only Account entity without any objects/components.

2.2. Open the Ribbon Workbech Tool from Solution or XrmToolBox.
       Here we are going to use RibbonWorkBench from XrmToolBox.
 

Now add the New button from left side Option => give button label and image => and Image icon(Here We are used the icon web resource of .png format)
Once you add your button you have to add the Command, Action, Enable Rule and Display Rule.

Friday, August 22, 2025

Read/Get The Dynamics 365 CRM/CE Current App Name Using Java Script

 Below code are used to get the current Dynamics 365 CRM Model Driven App Name.

Xrm.Utility.getGlobalContext().getCurrentAppName().then(

        function (appName) {

        },

        function (error) {

        }

    );


Example:
Read the current Model Driven App Name, If App Name is Sales Hub then Contact entity/table Account Name(lookup) field make the mandatory, otherwise not.

function getCurrentModelDrivenAppName(executionContext)
{
let formContext = executionContext.getFormContext();
Xrm.Utility.getGlobalContext().getCurrentAppName().then(
function (appName)
{
if (appName == "Sales Hub")
 {
   formContext.getAttribute("parentcustomerid").setRequiredLevel("required");
}
else
 {
formContext.getAttribute("parentcustomerid").setRequiredLevel("none");
 }   
},

function (error)
 {
alert("error " + error.message);
});

}


Read/Get The Dynamics 365 CRM/CE Logged In User Security Role Using Java Script

Below code are used to read/get the logged in user security roles.

let roles = Xrm.Utility.getGlobalContext().userSettings.roles;


Example:
Requirements:
Read the logged in user Security Roles and check the user is having Basic User and Sales manager roles, If have then show the Contact Job Title field otherwise hide it.


function checkRoles(executionContext) 
{
    let formContext = executionContext.getFormContext();
    let hasRole = false;
    let roles = Xrm.Utility.getGlobalContext().userSettings.roles;
    // ["AB Roles", "Sales Manager", "System Administrator"]
    roles.forEach(x => {
        if (x.name === "Basic User" || x.name === "Sales Manager") {
            hasRole = true;
            return;
        }
    });
    if (hasRole === true) {
        formContext.getControl("jobtitle").setVisible(true);
    } else {
        formContext.getControl("jobtitle").setVisible(false);
    }
}

Wednesday, August 6, 2025

What is Power Apps ?

In this post we are going to explain .

What is Power Apps?

A PowerApps is a low-code application development platform from Microsoft that enables users to create custom business applications without extensive coding knowledge. 

It is part of the Microsoft Power Platform, designed to help businesses automate processes, integrate with various data sources, and build interactive, user-friendly apps quickly. 

PowerApps allows users to create mobile and web apps that can connect to multiple data sources, including Dynamics 365, SharePoint, Excel, and external services etc.

Using this Power Apps you can develop and build following below business applications.
1. Model Driven Application
2. Canvas Application
3. Custom Page
4. Power Automate
5. Power Pages
6. Power BI
7. Power Virtual Agent

Hide And Show The Dynamics 365 CRM Button Based On Logged In User Security Roles

 In this post I am going to explain how you will hide and show the Ribbon/Command buttons based on logged in user security rule. I have one ...