Tuesday, February 24, 2009

Abort event through plugins

Suppose you are writing a pre -event plugin in which you compare to 
old and new values and on certain condition would like to cancel the Save or 
Update and stop the execution, it was simple in CRM 3 with an Abort() method
while in CRM 4, you have to manually raise and throw a 
Invalid-Plugin-Exception, while this gives a dirty error message on your MSCRM screen,
you can make it better by entering you own Message explaining why the record could
not be saved:

throw new InvalidPluginExecutionException("Execution has been stopped due to this reason");

Thursday, February 19, 2009

IME Mode in MSCRM attribute settings

When you create a new attribute for a MSCRM entity or open an exisitng one to see it's characteristics like data type, min-max values and schema name, you would have seen a property called IME mode, if you would've wondered what it is like me, here is what is got from the MSCRM Online resources

An Input Method Editor (IME) lets you to enter and edit Chinese, Japanese, and Korean characters. These Asian writing systems have more characters than can be encoded for a regular keyboard. The IMEs for these languages use sequences of base characters that describe an individual character or group of characters to enter a larger set of characters. Base characters can be component letters from Hangul syllables, phonetic components for Japanese kanji characters, or various combinations for Chinese characters. You can use the IME mode option to quickly enter these characters and symbols into text boxes, avoiding the manual switch to IME mode that would otherwise be required.

Input Method Editors have two principle states, inactive and active. The inactive mode behaves like a regular keyboard and uses a limited set of characters. The active mode accepts Chinese, Japanese, or Korean characters.

The following IME modes are available:

  • auto (default) 
    The IME mode is not affected with this choice.
  • active 
    All characters are entered in the IME mode, but you can still deactivate it. For name-related fields and addresses, the default is active for detailed forms.
  • inactive 
    All characters are entered without using the IME mode, but you can still activate it. For datetime type fields, the default is inactive for detailed forms.
  • disabled
    The IME mode is disabled, and you cannot activate it. For number type fields (money, int, float), the default is inactive for detailed forms.

Friday, February 13, 2009

Mail merge fields limit in MSCRM

The maximum number of fields that can be added
 to a mail merge document in MS CRM is 62

Retrieve custom entity and attributes by Microsoft.Crm 4 Sdk

CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = "";
token.AuthenticationType = 0;
Microsoft.Crm.SdkTypeProxy.CrmService service = new Microsoft.Crm.SdkTypeProxy.CrmService();
service.Url= "http://localhost:5555/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.UnsafeAuthenticatedConnectionSharing = true;


Microsoft.Crm.Sdk.Query.QueryExpression query = new Microsoft.Crm.Sdk.Query.QueryExpression("mycustomentity");




query.Criteria.AddCondition("name", ConditionOperator.Equal, "Chandresh");


RetrieveMultipleRequest requestAccount = new RetrieveMultipleRequest();

requestAccount.Query = query;

requestAccount.ReturnDynamicEntities = true;


RetrieveMultipleResponse result = (RetrieveMultipleResponse)_crmService.Execute(requestAccount);


if (result.BusinessEntityCollection.BusinessEntities.Count > 0)


DynamicEntity myEntity = (DynamicEntity)result.BusinessEntityCollection.BusinessEntities[0];

string strName = "";

string intNumber = 0;


if (myEntity.Properties.Contains("number"))

intNumber = ((CrmNumber)myEntity.Properties["number"]).Value;


if (myEntity.Properties.Contains("name"))

intNumber = myEntity.Properties["name"]).ToString();




Tuesday, February 3, 2009

Extra events in MS CRM entity form

When you want to make some updates in CRM on the entity form like set certain values
or do some computation, two events you can rely on is onLoad and onSave.

What if users don't want to press a button, say Save, especially in the case of a record of a related entity being added or created with the entity of which form you have opened, there is no way to track the updated in number of records being added or removed from the related entity, what you do then other than OnSave ? 

Classic javascript has the answer, like any other webform, you get standard window events like onload, onunload: which is the event to be called when you close the window, i.e click on the rightmost cross button [X] at anytime, and also onblur: which is when you move on the another window or just go to desktop loosing the focus of the active window which is the MS CRM form. 

So you can run some javascript code on these events by defining a custom handler function for these events which would not be handled by default and have the value null.

This is done in the onLoad event of the MSCRM form: