Wednesday, July 29, 2015

How to set header field value in Dynamics CRM form?



Setting the header field values is not supported in xrm. So, we must move to unsupported ways to set the value of the fields added in header.
Following code snippet will help us to achieve the goal.

document.getElementById("header_xxx_d").childNodes[0].innerText = value;

In the above code snippet, replace xxx with your field name that exists in the header and value with your value you need to set.

But it'll not save in the database. To achieve this you should add a hidden field on  the form and set its value when you are setting value for the header field and then at  on-load event again get the value and assign to the above code snippet.

Cheers!


Tuesday, July 28, 2015

How to Enable/Disable a custom button for specific roles in Dynamics CRM??



I just came across with an urgent requirement to add a custom button in to main ribbon and then enable it if user has CSR Manager Role and disable in other case. It can be done through many ways as you can find multiple blogs posts written on it. But I found a simplest way to do it.
Here it is:
  1. Find guid of CSR Manager Role using the following code:

    function CheckUserRole(){
    //get guid of all assigned roles
    var currentUserRoles = Xrm.Page.context.getUserRoles();
    for (var i = 0; i < currentUserRoles.length; i++) {
            
    var userRoleId = currentUserRoles[i];
             //alert to each role
           
    alert(userRoleId);
    }   
    return false;
    }
  2.  In the following code, I’m checking if array contains the guid of a CSR Manager Role

    function ifCSRManager() {
    //get  guids of the roles assigned to user
    var currentUserRoles = Xrm.Page.context.getUserRoles();
    //check if it contains the guid of CSR Manager
    if (currentUserRoles.indexOf("1117f744-a5bd-e411-8c0a-005056b04acd") > -1)
     
    {    return true;}
    return false;
    }
Now, in ribbon workbench just add custom javascript role in enable rule and then tie it with command of the button.

Step # 1: Add new Enable Rule


Step # 2: Right click on the rule and then Edit Rule 

Step # 3: Select Custom Javascript Rule and click OK 

Step #4: Give Function Name and Library that contains function and click OK 
Step # 5: Add this rule to the command tied with your custom button and publish solution.




Friday, July 10, 2015

How to use XRM Service Toolkit in Microsoft Dynamcis CRM Forms??

XrmServiceToolkit is a JavaScript library which can be used for JavaScript Development under the platform for Microsoft Dynamics CRM 2011/2013/2015 environments. The library contains four major parts regarding functions.Like, General Methods used for various purpose,Rest, Soap and other jQuery extension to utilize WebResource to extend CRM 2011 / CRM 2013 / CRM 2015 including dependent OptionSet, field tooltip, add custom filter view to lookup field.

How to use the XRM Service Toolkit
  1. Download toolkit from here
  2. Extract the downloaded zip.
  3. Open the solution in Microsoft Dynamics CRM
  4. Create New web resource give its ‘Name’, ‘Display Name’, Select the ‘Script(JScript)’ from Type and then browse for the jQuery file that comes with the XRM Service Tool Kit
  5. Create two more web resource for json and XRMServiceToolKit, by repeating the step ‘4’
  6. Add all these web resources to a form in the following order:
    i. jQuery
    ii. jSon
    iii.XrmServiceToolkit
    iv.Your web resource library

Enjoy!