Showing posts with label XRM. Show all posts
Showing posts with label XRM. Show all posts

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



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

Thursday, September 21, 2017

Custom XRM Library: Enhance functions

Custom XRM Library to enhance the functionality of xrm functions. This library is a small effort from my side. This includes validations and avoid null reference exceptions in javascript.

I am improving it and planning to add more functions and improvements.

Download

Friday, November 6, 2015

Lookup Filter Through XRM


In below example, I have implemented custom filter on Student Course Lookup. This filter is forcing the student courses to show for the given Student Id. Student Id is mapped as single line of text field so default filter functionality can not be implemented for Student Course Lookup.

Student Course Lookup Before Filter














Student Course Lookup After Filter 














Xrm Code

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

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