Posts

Showing posts from 2013

Exception Handling Tips for JavaScript in MS CRM 2011 Ribbon

Image
When there is an error in JavaScript code of the event handlers on CRM forms, there is an alert for the error message.

But when there is an error in JavaScript code used in EnableRule or Actions of CRM ribbon buttons, there is no error message showing and we can only see the form just loading partially, "Error on page" showing at the status bar of the window, or sometimes just nothing happen on button click.

It becomes a big problem when the developer update the codes here and there in a lot of functions without updating and testing bits by bits. If we find out there is an error after updating multiple functions and deployed at once, we would not be able to pinpoint the source of the error without any error message.

So, it is best practice to do exception handling for each and every functions used in EnableRule or Actions of CRM ribbon buttons as in the example below.


function EnableDisableTestButton() { try { // Button custom rule checking …

Creating Forward Email through SDK

Here's the sample code to create Forward Email through SDK
private static Guid CreateForwardEmail(Guid existingEmailID) { Entity existingEmail = _service.Retrieve("email", existingEmailID, new ColumnSet("from", "createdon", "to", "cc", "subject", "description", "regardingobjectid")); Entity oEmail = new Entity("email"); oEmail["regardingobjectid"] = existingEmail["regardingobjectid"]; oEmail["subject"] = "FW: " + existingEmail["subject"]; oEmail["description"] = "<FONT size=2 face='Tahoma, Verdana, Arial'><BR>------------------- Original Message -------------------<BR>"; oEmail["description"] += "<B>From:</B> " + ((EntityReference)((Microsoft.Xrm.Sdk.EntityCollection)existingEmail["from"]).Entities[0]["partyid"]).…