In ribbon button customization, it is a common scenario to show the button only to a certain set of users who have a certain security role.
Security Role Scenario
Let’s assume Subscription Manager is a security role in your Dynamics 365.
And the Ribbon button will only be visible to the Users who have been assigned this Security Role.
If they have this Role, they’ll be able to see the button as below
And, if the Role is not assigned, the logged In user won’t be able to see the Button.
See below that in this case, the button will not show up.
JavaScript Code to check assigned Security Roles to the logged in User
Since we are going to use a CustomRule further in the Ribbon Workbench to pick a true or false value based on whether the logged in user has a Security Role or not, let’s write a quick JavaScript function to provision the same.
Tip: Make sure you now pass the PrimaryControl (context) to any JS functions and avoid using Xrm.Page since the same has been deprecated.
// JavaScript source code
contactFormCustomization = {
checkSubscriptionAccess: function (context) {
"use strict";
debugger;
var currentUserRoles = context._globalContext._userSettings.securityRoles;
var roleId = "BA69EA1F-A76E-EB11-A812-000D3A1948AB"; // Subscription Manager role
roleId = roleId.toLowerCase();
// Get all the roles of the Logged in User.
for (var i = 0; i < currentUserRoles.length; i++) {
var userRoleId = currentUserRoles[i];
if (userRoleId == roleId) {
// Return true if the Role matches
return true;
}
}
return false;
}
};
Hard-code the GUID of the Security Role which you are looking to check.
Then read all the Security Roles assigned to the user.
Once the Security Roles are found in the logged in User’s Security Role, return true. Else, return false.
Ribbon Button – Enable Rule
Let’s see how the button customization will look like in XrmToolBox’s Ribbon Customization –
In Ribbon Workbench, you need to add a CustomRule under Enable Rules for the Ribbon button.
Then, it asks for the JavaScript function (mention the function which returns a simple true or false based on above steps). and then mention the library – Also, pass the context PrimaryControl and using the same, pick the Security Roles of the logged in user as mentioned in the JS code explanation above. I’m naming my Enable Rule as SecurityRoleCheck.
Now, the CustomRule I’ve applied will call the JS function and is expected to receive either a true or a false based on the code. If false – the button will not be enabled, if true – the button will be enabled.
Now, make sure you add this Enable Rule to the Command (which is in-turn attached to the Ribbon Button itself)
Hope this was helpful. Here are some more XrmTool / Ribbon Button customization related posts you might find helpful –
It has always been recommended to enable MFA on environments we work on. For developers, it is especially critical that MFA is enabled that developers are also someone who need to connect the https://www.xrmtoolbox.com/ more than ever!
Here’s one of the common challenges in being able to connect to an MFA enabled Dynamics 365 instance using XrmToolBox.
Register the Dynamics 365 environment as an App in Azure
Once you save it, you’ll get the Application (client) ID which which will be needed by the XrmToolBox while connecting.
Go to the Manifest file and make “allowPublicClient” to true and Save it.
Now, navigate to API Permissions from the left side menu.
Now, search for the permission “Common Data Service” under the tab APIs for my organization uses.
Make sure Delegated Permissions are selected and tick mark user_impersonation and click on Add permissions.
Select the same and your permissions should look like below. Once this is the state, you are done on Azure side.
Now, let’s connect XrmToolBox to the Dynamics 365 environment.
Connecting to Dynamics 365 using the XrmToolBox
Let’s see what steps you need to follow in order to connect to the Dynamics 365 instance
Open XrmToolBox and create a New Connection.
Now, since you are aware that the environment is MFA enabled, select MFA/OAuth method.
Enter the URL of the Organization and click Next as shown below.
Now, enter the Application ID which you can copy from the registered App in Azure.
If you click on the “Use development Azure AD App”, the Reply Url will be populated automatically. Before that, you’ll see the message notifying which scenarios this is suitable.
Read below. At this point, I haven’t tried the other method and stuck to the below since I connect XrmToolBox to the Dynamics 365 environment for development purpose.
Once you click OK on the above, the Reply Url will be auto-populated and you can proceed further.
Now, enter the username which you want to connect with. Supposedly, this is the one on which MFA is enabled.
Upon clicking Next, you will be asked the Password of the credentials you are using.
Once you’ve entered the same, it will send a request to your Authenticator on the registered device.
One the device, assuming you have the Authenticator App installed already, you can Approve the same to let the Authentication go through.
Upon Approval, the XrmToolBox will be authenticated and it will be connected to the Dynamics 365 environment. As usual, you can then give it a name and click Finish to save it on your XrmToolBox.
Hope this was helpful!!
Here are some more Azure / Dynamics 365 / XrmToolBox related posts you might want to check out –
Most of us have been used to using the classic form designer as of now. And the Power Apps UI which is in https://make.powerapps.com/ has some important new features.
We create forms and we then have to explicitly make sure we have assigned them correct Security Roles and added them to the Apps correctly.
So the new Power Apps Form Designer has a very useful feature called as Form Access Checker. Let’s look at it
A Form & An App
Let’s say we have a custom/Unmanaged Form called as ‘Management Form’.
And an App called as ‘Management App’.
And it has Contact entity with 2 Forms added.
And here are the 2 forms – Contact (OOB) and Management Form (Custom)
Form Access Checker
The Form Access Checker answers 2 questions at once – Let’s look at this feature
Open the form and go to Form Settings.
In the Form Properties, look for Form access checker.
Now, select the Security Role you want to check for and then the App you want to check. The Form Checker will show the Forms which satisfy either and both the criteria.
Now with only Salesperson role, below are the forms which are applicable. Note that the App is not yet selected.
Now, if you choose the App – the Form that matches both these will be selected.
And it’ll show only the Forms which are applicable to both criteria. (Notice that the form we added in the Management App didn’t show up)
Now, let’s give the Management Form we added Salesperson Security Role and see it satisfy the above criteria. You can now assign Roles to a Form within the Form designer itself.
And if you check again, you’ll be able to conclude that the App we are looking for has both these forms for the Security Role you want to check
Hope this helps. Here are some more Dynamics 365 related posts you might want to check out –
Note: Since these are Early Access Features, not all features would necessarily make it to the final Wave 1 2021 release. Kindly try these features in a Sandbox environment only and test the same.
Microsoft Teams’ connector for Cloud Flows (Power Automate), and if you are looking to use Adaptive Cards for Microsoft Teams from the connector. There are chances that you’ll see some options to post an Adaptive Cards to Teams.
I’m exclusively covering a Teams’ connector’s Action called as Post an Adaptive Card to a Teams user and wait for a response.
But, you also have an improved Adaptive Cards Action in the Microsoft Teams’ connector that let’s you save the progress of the Card in the Flow itself!
Also, I found this effective for only 1 Action from the Microsoft Team’s Adaptive Card related actions. Not others.
Adaptive Card to Teams User – Regular
So, if you see the below –
With the above Adaptive Card, you’ll need to work in https://adaptivecards.io/ and paste the Card payload here and then save it. Also, you can’t visualize it within the Flow step itself.
Turn on Experimental Features for Flow
Look for the Gear icon in Settings and look for All Power Automate Settings
If the Experimental Features show below is turned Off, please turn it on.
Adaptive Card with Experimental Features On
Now, if you select the same Action from the Power Automate step
You’ll see the Step Action having the below details.
Once you click on Create Adaptive Card, you’ll see the Designer itself in the Flow Steps which you can create the Card on the fly within the Flow and save the same as well.
Hope this helps!!
Here are some more Power Automate posts you might want to look at –
Now, let’s say you want to be able to select a few Gallery Items and the same should be populated to a Gallery and even from Collection as well.
You can use this scenario if you want to create a Collection of some GUIDs/Account Names and then take separate action on it or handle it in some other context.
Add Check box in a Gallery
Let’s take a simple example-
I added a Check Box in a simple Gallery list.
Align as per your preference. It also comes with a Default “Option” label which you can remove.
Now, there are 2 properties which you can use to add to a Collection and remove from the same collection. Let’s look at the first one – OnCheck
Under OnCheck function, I’ll add the current item to the Collection (A new collection will be created if not already created) Bluedenotes function used to create a Collection. Collect() function – Microsoft Documentation on the Collect() function – https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-clear-collect-clearcollect?WT.mc_id=DX-MVP-5003911 Green arrow denotes the name of the Collection I’m creating. Red arrow denotes the current Item from the Gallery control and the Account Name field which I want to populate in my collection. This will add the Account Name of the record to the Collection once the Check box is checked.
Under OnUncheck function, I’ll add the formula to remove the current Item from the Collection. Blue denotes the function used to remove a value from the Collection. Microsoft Documentation of the same is here – https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-remove-removeif?WT.mc_id=DX-MVP-5003911 Green arrow denotes the name of the Collection from which I have to remove the value. Red arrow denotes the current Item which I had added to the Collection when the Box was checked. It’ll use the same reference. This will Remove the Account Name which was added to the Collection when the checkbox was checked.
For simplicity, I’m taking Account Names to show in the Collection, you can create a structure in Collection and map Item values as per your needs.
Changes in Collection (Using Data table to visualize)
Just to show/visualize how the Collection will look when I interact with the Check boxes on the Gallery, I’ve added a Data table to keep the demonstration simple.
And populate the Items with the Collection’s Value. Because all the Account Names we added to Collection while marking Check box as Checked will fall under .Value
Working
As you select and unselect items from the Gallery, they are added to and removed from the Collection which is seen in the Data Table below.
Hope this helps!!
Here are some more Canvas Power Apps related posts you might want to check out –
Recent Comments