Pages

Tuesday, August 2, 2011

Adding a Form Ribbon Button in CRM 2011

In CRM 4.0 it is possible to add a button to the body of a CRM form and there were many good reasons to do so. While this is still possible in CRM 2011, I would argue that it's no longer relevant with the introduction of the ribbon interface which allows a lot more granular control over the behavior and function than was available using ISV.config in CRM 4.0.

There are a number of good articles that walk through the technical process of adding a ribbon button that you can refer to. The following is a high level visual representation of adding a button that executes a custom action that should hopefully bring this all together succinctly. This article assumes you have read through some of the other literature that describes how you go about exporting, identifying, and editing the entity customization file that you wish to add a button to.

Please refer to the screenshot below.



The following are some of the more important sections of the edits that need to be made:

  1. CustomAction Id - Add an id here that uniquely identifies the custom action you are adding
  2. CustomAction Location - Identifies the ribbon to update. If you are updating an account, it will start with Mscrm.Form.account, if you are updating a lead it will start with Mscrm.Form.lead etc.
  3. CustomAction Sequence - Identifies where in the ribbon it will appear
  4. Button Id - Add an id here that uniquely identifies the button you are adding
  5. Button Command - Add a command name
  6. LabelText/Tooltips - Any descriptive text
  7. TemplateAlias - Defines how the button appears although I haven't delved very deep into this one yet. Default to "01". 
  8. Images - Reference 16 and 32 icons that you should add as a web resource to your environment (optional)
  9. CommandDefinition Id - This should match the Button Command referenced in step #5. 
  10. Command Definition Actions - This section defines the action to take when clicking the button. There are various actions that can be taken. The first example is commented and simply would take the user to a web page when clicked. The second example is a reference to a custom jscript function defined in the form jscript. I chose to reference the "default" contact library but this could be any jscript library.
  11. Function HelloWorld - The function in the second example above must be created in the relevant jscript library and should match the FunctionName from the CommandDefinition section
  12. Xrm.Page.ui.refreshRibbon - This is a command that you can optionally add to jscript. Some times after you click a ribbon button, you will want to disable that button or perhaps enable another button on the ribbon. By callling this command at the end of your jscript function, you instruct the ribbon to refresh and re-execute any of the Enable and Display rules to control the appearance of your button which I discuss in my next post.

That's it. Now when you click the ribbon button, you will receive a "Hello World" alert prompt.

That's a brief introduction to the topic. Refer to the CRM SDK for more configuration options.

No comments:

Post a Comment