Security roles JS updates

UCI has plenty of new features, one it is security roles fetch is very good one though did not creek. Good thing about it is, it will gives us all security roles along with its name in userSettings itself.

Here is code snippet of it

// Get Logged In User's Context
     var userSettings = Xrm.Utility.getGlobalContext().userSettings;
     // Get Logged In User Security Roles
     var loggedInUsersecurityRolesGuids = userSettings.securityRoles;
     var loggedInUsersecurityRoles = userSettings.roles;
     var isUserAdmin = false;
     for (var i = 0; i < loggedInUsersecurityRolesGuids.length; i++) {
     if (loggedInUsersecurityRoles._collection[loggedInUsersecurityRolesGuids[i]].name === "System Administrator" ||         loggedInUsersecurityRoles._collection[loggedInUsersecurityRolesGuids[i]].name === "*System Administrator")     
{ isUserAdmin = true; } }

if (isUserAdmin) {
//do something      
     }

Thanks.

Open dynamics record in dialog/Modal popup using navigateTo Client API

In 2020 Release Wave 1 Update for Dynamics 365 introduced navigateTo Client API to open main form of dynamics record in dialog instead Xrm.Navigation.openForm. This helps record to open in new window or same window of browser.

Below, we have provided information about how to open the CRM record in dialog. So to open new form for the entity is by below code snippet ..

var parameters = {};
             parameters["soft_para1"] = formContext.data.entity.getId();
             parameters["soft_para2"] = formKeyString;
             parameters["soft_para3"] = 1;

var pageInput = {
             pageType: "entityrecord",
             entityName: "soft_entityLogicalName",
             data: parameters,
             formId: "71ca9461-3209-4740-bd62-7320af2ae89c"
         };  


Xrm.Navigation.navigateTo(pageInput, { target: 2 }).then(
         function success() {
             //do something 
             //do something
         },
         function error() { }
     );

To open existing record use below code snippet

var pageProperty = {
                     pageType: “entityrecord”,
                     entityName: “contact”,
                     formType: 2,
                     entityId: “979dfe31-0686-ea11-a811-000d3a579c9c”//guid of record
                  };

var navigationProperty = {
                 target: 2,
                 width: { value: 80, unit: “%” },
                 position: 1
               };
Xrm.Navigation.navigateTo(pageProperty, navigationProperty);

Now, to show some custom html page

var dialogParameters = {
 pageType: "webresource",//required
 webresourceName: "ab_/ModalDialog.html",//Html Webresource that will be shown
 data: data//optional
};
 
var navigationOptions = {
 target: 2,//use 1 if you want to open page inline or 2 to open it as dialog
 width: 400,
 height: 300,
 position: 1//1 to locate dialog in center and 2 to locate it on the side
};
 
Xrm.Navigation.navigateTo(dialogParameters, navigationOptions).then(
 function (returnValue){
 //you can add handling of resultValue here
 console.log(returnValue);
 //put your success handler here
 },
 function(e) {
 //put your error handler here
 });

hope it helps.

Thanks!

Get the list of the dirty fields on the Dynamics 365

To quickly get the list of all the dirty fields

Open the debugger tool and put the following script in the console window

Xrm.Page.data.entity.getDataXml();

Get logged in user’s Security roles names in UCI

Here is sample code to get security roles name of logged in user.

function GetLoggedInUserSecurityRoleNames() {
 // Get Logged In User Context
 var userSettings = Xrm.Utility.getGlobalContext().userSettings;
 // Get Logged In User Security Roles
 var loggedInUsersecurityRolesGuidArray = userSettings.securityRoles;
 var totalSecurityRolesArray = new Array();
 var rolesOutputText = "";

if (loggedInUsersecurityRolesGuidArray.length > 0) {
 Xrm.WebApi.retrieveMultipleRecords("roles", "?$select=name,roleid").then(
 function success(result) {
 if (result.entities.length > 0) {
 // Push Role Names and Role Ids to Array
 for (var rolesCount = 0; rolesCount < result.entities.length; rolesCount++) {
 totalSecurityRolesArray.push({ RoleName: result.entities[rolesCount].name, RoleId: result.entities[rolesCount].roleid });
 }

rolesOutputText = userSettings.userName + " has the below Security Roles\n------------------------------------\n";

// Compare the User Security Roles with Total Security Roles
 for (var userSecurityRolesCounter = 0; userSecurityRolesCounter < loggedInUsersecurityRolesGuidArray.length; userSecurityRolesCounter++) {
 for (var totalsecurityRolesCounter = 0; totalsecurityRolesCounter < totalSecurityRolesArray.length; totalsecurityRolesCounter++) {
 if (totalSecurityRolesArray[totalsecurityRolesCounter].RoleId.toLowerCase() == loggedInUsersecurityRolesGuidArray[userSecurityRolesCounter].toLowerCase()) {
 rolesOutputText += totalSecurityRolesArray[totalsecurityRolesCounter].RoleName + "\n";
 break;
 }
 }
 }
 }

// Show User Roles
 Xrm.Utility.alertDialog(rolesOutputText, null);
 },
 function (error) {
 // Show error
 Xrm.Utility.alertDialog(error.message, null);
 });
 }
}

Duplicate workflows in advanced find – CRM 365

While searching for the process in the Advanced Find of my MS Dynamics CRM 365 environment, I noticed that several “duplicates” of the process appeared. Although they had the same name, some of them were in Draft Mode and two were Active. One curious thing that I saw was few processes are same logic and steps, also, whenever I did a change in one of my Active workflow/business rule, the other was replicating the change. This made me had a hard time trying to figure out what was happening, specially because after searching the duplicates in the Default solution to delete them, only one appeared.

Continue reading “Duplicate workflows in advanced find – CRM 365”

Xrm.WebApi.online.execute (Client API reference) in MSD 365

Xrm.WebApi.online.execute(request).then(successCallback, errorCallback); can be used for CURD operations, also to execute workflow and action. In the above syntax ‘request’ will be a object which can have all information of the operation. The details of the request can be found here in more depth. Here is some details ..

Continue reading “Xrm.WebApi.online.execute (Client API reference) in MSD 365”

Activate-Deactivate Plugins/Process with code

while deploying our customisation to target environment many times we need disable/deactivate plugins and or process. Manually, its straight forward but what about when you are working with DevOps or you cannot touch target environment. In such environment, we need to handle it with code. So for that here are the steps …

Continue reading “Activate-Deactivate Plugins/Process with code”

System jobs in Dynamics

For DevOps, we have to handle each and everything from code behind and in automated way. Thus, wrote code to create manage System jobs to delete records every night in Dynamics. Here are the main points from my understanding ..

The BulkDeleteRequest message will create a bulk delete job that will be automatically executed on a specified interval for a specified set of data.  The job will be executed by the CRM Asynchronous service.

Continue reading “System jobs in Dynamics”

Pass parameter to RDL

Sometime we need to send parameter dynamically to SSRS report, to achieve it below JS function will help … here key thing is “&p:”, whatever next to this one will be considered as parameter, e.g. “&p:parameterName=parameterValue”. You can pass more than one parameters too.

Continue reading “Pass parameter to RDL”

Reports in MSD 365

To create SSRS report for MSD 365, we need SQL Server Data Tool, its part of Visual studio itself. To create report follow the below steps ..

Continue reading “Reports in MSD 365”