The new Client Side API adds a very easy way of adding new buttons.

crm.addButton(imageURL,captionfamily,captioncode,[options])

The new Client Side API allows application extensions to be called. This would typically mean calling either an ASP page or a .NET assembly. In order to do this we need to be able to make sure that context is maintained and that we have control over any other variables that need to be passed.

To understand this we can look at how we can

  1. Call a standard System Action
  2. Call an ASP Page
  3. Call a .NET Assembly

Call a Standard System Action

The image below shows a button that has been added to the Company Summary screen. The button will call the Mail Merge system action.

The button is added by the following code being included in the Custom Content box of the CompanyBoxLong screen

[code language="javascript"]
<script>
crm.ready(function(){
var buttonimage = '..\\Themes/img/color/buttons/mailmerge.gif';
var buttonaction = crm.url(542);
crm.addButton(buttonimage,'Tabnames','document',buttonaction);
})
</script>
[/code]

Note: The method crm.url() will ensure the URL that is generated includes all of the current context information. The System Action for the Mail Merge was obtained by reading the 'Act' code included in the URL of the standard mail merge screen.

Call an ASP page.

In the example below a button that has been added to the Company Summary screen that will call an ASP page.

[code language ="javascript"]
<script>
crm.ready(function(){
var buttonimage = '..\\Themes/img/color/buttons/progresscase.gif';
var buttonaction = crm.url('myasp.asp');
crm.addButton(buttonimage,'Button','Progress',buttonaction);
})
</script>
[/code]

Call a .NET Assembly

Below is some example code that shows how to add a call to the RelatedEntities feature on the Company Sumary page.

The code needs to be added to the Custom Content box of the CompanyBoxLong screen.

[code language="javascript"]
<script>
crm.ready(function(){
//function script goes here
var buttonimage = '..\\Themes/img/color/buttons/ExpandSelectedNode.gif';
var buttonaction = crm.url('RelatedEntities.dll-RunREList');
crm.addButton(buttonimage,'Tabnames','Relationships',buttonaction);
})
</script>
[/code]

Note: A later article will discuss how the presentation and positioning of these button can be improved in the page by passing an 'options' object as the 4th parameter of the crm.addButton() method.