Friday 26 October 2012

Dynamics CRM 2011 - Propagate the plug-in invalid exception message in JavaScript code.

Recently I came across an issue where I would like to propagate the plug-in InvalidPluginExcecutionException message via JavaScript code. Based on the client requirements I need to trigger a plug-in on click of custom ribbon button on the Opportunity entity. Hence on custom button click I have written a web service call that updates one of custom attributes of an Opportunity entity. So, when system will update this field via client side web service call, the registered plug-in will be triggered automatically.

Usually your InvalidPluginExcecutionException message inside your plug-in code is displayed to user in a standard CRM message box. In my case I am unable to see the same because the plug-in is being triggered via JavaScript web service call. Below is the code snippet that executes my query.

//Asynchronous AJAX function to update a CRM record using OData
  $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    data: jsonEntity,
    url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')",
    beforeSend: function (XMLHttpRequest) {
      //Specifying this header ensures that the results will be returned as JSON.             
      XMLHttpRequest.setRequestHeader("Accept", "application/json");
 
      //Specify the HTTP method MERGE to update just the changes you are submitting.             
      XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
    },
    success: function (data, textStatus, XmlHttpRequest) {
      //The MERGE does not return any data at all, so we'll add the id 
      //onto the data object so it can be leveraged in a Callback. When data 
      //is used in the callback function, the field will be named generically, "id"
      data = new Object();
      data.id = id;
      if (successCallback) {
        successCallback(data, textStatus, XmlHttpRequest);
      }
    },
    error: function (XmlHttpRequest, textStatus, errorThrown) {
      if (errorCallback) {
 
        errorCallback(XmlHttpRequest, textStatus, errorThrown);
      }
      else {
        ErrorHandler(XmlHttpRequest, textStatus, errorThrown);
      }
    }
  }); 

I have validated all the 3 objects i.e. XmlHttpRequest, textStatus and errorThrown inside errorCallback method to seek the plug-in error message with no success. However I can see the same error message via fiddler!!

Finally, I found a way to parse the response text of xmlHttpRequest and get the exact error message. Below is the code that works for me to alert the plug-in message from client side code.



function ErrorHandler(xmlHttpRequest, textStatus, errorThrown) {
 
  alert(JSON.parse(xmlHttpRequest.responseText).error.message.value);
 
}

I hope this will be helpful.

Saturday 13 October 2012

Dynamics CRM 2011 - Role Updater

Role Updater makes it easier for administrator and developers to add/ remove privileges to multiple roles at a single time.

Download this tool with the help of below link

http://roleupdater.codeplex.com/

Role Updater is available as an executable. Run the exe and a window is displayed as viewed in screenshot below

clip_image002

You can add a new Connection or select an existing connection. After selecting the connection press the orange button as highlighted in below screenshot and you will be asked for your credentials

clip_image004

If you still find the loading message click on the highlighted button once again. You will see a window as displayed in the screenshot below. Select the roles for which you want to change privileges

clip_image006

Add/Remove privileges from the window that is displayed on selecting role and clicking next.

clip_image008

On clicking next the roles are updated and a window is displayed as viewed in screenshot below.

image

Friday 5 October 2012

Dynamics CRM 2011 - View Layout Replicator

 

As the name suggests View Layout Replicator is useful for replicating same view layout in other views of same entity.

You can download the View layout replicator from

http://viewlayoutreplicator.codeplex.com/

clip_image002

Run the View Replicator executable file and a window is displayed as viewed above .Select Load Entities as highlighted in image above you will get a window to select connection as viewed above. You can even add a new connection from this window.

Select an entity from the list and the views of the entity are loaded as Source Views and Target Views.

clip_image004

Select the view which you want to change as ‘Target View’ and select the view to which you want to replicate as ‘Source View’.

clip_image006

After selecting Source and target views select the Save Views option as highlighted above. A message is displayed as above. Select the ‘Publish Entity’ option which is next to the highlighted option. On publishing the entity the changes are reflected in the view.