Saturday, March 31, 2018

Check User Specific Role - Web API - Dynamics CRM 365

In this post, I am going to demonstrate how to check that current logged in user has specific role or not in Dynamics CRM 365 using JavaScript & Web API.


function IsRoleExist(RoleName) {
    var currentUserRoles = Xrm.Page.context.getUserRoles();
    for (var i = 0; i < currentUserRoles.length; i++) {
        var userRoleId = currentUserRoles[i];
        if (GetRoleName(userRoleId) == RoleName) {
            return true;
        }
    }
    return false;

}

function GetRoleName(RoleId) {
    var select = "roles(" + RoleId + ")?$select=name";

    var result = AWXRM.WebAPISelectVersion(select, "8.2");
    var Rolename = result["name"];
    return Rolename;

}

function OnLoad() {

var Role_Admin = "System Admin_1";
var IsRoleExist = null;

   if (IsRoleExist(Role_Admin))
            IsRoleExist = true;
        else
            IsRoleExist = false;
}

Dependency:
Need this library to be included in form load / page load
AWXRMLibrary


㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤
Ali Hamza Wadood 
Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC)
LinkedIn



Enable Rule for Default Buttons - Ribbon Workbench - Dynamics CRM 365


1) Install Ribbon Workbench from here
2) Import solution in your Dynamics CRM 365 instance
3) A button "RIBBON WORKBENCH 2016" is created in Solution Page. Click on it
























4) Now new window is opened. Select your desired solution containing entity to be customized. It is better to create a separate solution to be used for ribbon customization and contains only desired entity. In this scenario I have created a new solution "Ribbon Solution" contain only Case entity. Here I am selecting solution Ribbon Solution

























5) Now solution is opened in ribbon workbench. Select your desired entity and on button right mouse click. Now select Customize Command. (In my case as button is already customized therefore this command is shown disabled)























6) Now in command section, select the generated command and click on Add Enable Rule. Now select Add New Enable Rule.




























7) Now click on Add Step & select CustomRule. There are others rules to apply enable rules on button. Here I am only showing the CustomRule.























Friday, March 30, 2018

Object Oriented Javascript - Dynamics CRM 365

I have done lot of work using javascript in Dynamics 365 (CRM) / CRM Projects. During many routine tasks I always used to think about how to optimize my code?, so able to do more with less code. Therefore achieve code reuse-ability, extensiveness and object oriented style. In below Javascript technique I am trying to demonstrate this approach.






function Customer() {

    this.name =  AWXRM.GetXRMAttributeGetVal("name");
    this.custid = AWXRM.GetXRMAttributeGetVal("accountnumber");
    this.address = AWXRM.GetXRMAttributeGetVal("wtr_plot");
    this.customertype = AWXRM.GetXRMAttributeGetText("wtr_customertype");
    this.cnic = AWXRM.GetXRMAttributeGetVal("wtr_cnic");
    this.phone = AWXRM.GetXRMAttributeGetVal("telephone2");
    this.cell = AWXRM.GetXRMAttributeGetVal("telephone1");
    this.guid = Xrm.Page.data.entity.getId();
    this.guidplan = this.guid.replace("{", "");
    this.guidplan = this.guid.replace("}", "");
    this.invoices = {};
    this.invoices.invoicedetails = {};

}

function OnSave(){

   var customer = new Customer();

}




㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤
Ali Hamza Wadood 
Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC)
LinkedIn

Saturday, March 24, 2018

Calling REST Web Service in Plugin


I was involved in a project where I have to consume REST Web services to integrate with Dynamics CRM 2016. Below plugin was used to perform this operation.

The web service used POST operation. and retrieved a specific authentication string present in response headers.



























Asp.Net MVC (5) - Exception Filter - HandleError

Applicable on Asp.Net MVC5 HandleError Filter This belongs to Exception Filters category (Authentication Filter, Authoriz...