Adding Buttons to a CRM From using Jquery
6/25/2012 UPDATE: This new version will work in either Header, Footer, Body or all!
In the post we are going to take a look at licking a problem that I have with Microsoft Dynamics CRM 2011. That is adding buttons to a form to perform some sort of action. There are several ways of firing script such as onchange of fields or even adding buttons to the ribbon bar. The ribbon bar is pretty interesting way of adding functionality, if you have the time download the definitions, find the exact spot and order you want your button, then finally re-import it. Its a cool feature and these new buttons are available for all forms for the entity, but it is overkill for simple things. This post will show you how to quickly add buttons to a page with just a few lines of javascript.
- This plugin requires Jquery, download the latest version and add it along with the CRMButtonBar plugin to the script collection for your form.
- Create a new attribute (a text field is fine) and add the new attribute to the form where you want the buttons to show up.
- Either add the following code to your main Javascript page or or create a new script page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | $(document).ready(function(){ $('#new_newname_d').CrmButtonBar ({ sourcefield: 'new_newname', buttons:[ { text : "Press Me", click: function (){alert("Button 1 Pressed");}, width : '50px' }, { text : "Press Me Too!", click: function (){alert("Button 2 Pressed");}, width : '150px' }] }); }); |
$(document).ready(function(){
$('#new_newname_d').CrmButtonBar ({
sourcefield: 'new_newname',
buttons:[
{
text : "Press Me",
click: function (){alert("Button 1 Pressed");},
width : '50px'
},
{
text : "Press Me Too!",
click: function (){alert("Button 2 Pressed");},
width : '150px'
}]
});
});When you’re done, your page should look similar like the following:
Thats all there is to it!






Hi,
can you explain how to call this function from the OnLoad Event?
Based on the code above, it run automatically on load via the jquery $(document).ready() function.
function OnLoad(){ $('#new_newname_d').CrmButtonBar ({ sourcefield: 'new_newname', buttons:[ { text : "Press Me", click: function (){alert("Button 1 Pressed");}, width : '50px' }, { text : "Press Me Too!", click: function (){alert("Button 2 Pressed");}, width : '150px' }] }); }Add the Onload Function to you page’s onload event.
Hi Brian,
Can you please give an example code, for creating new buttons in Ribbons section.
Please..
Yes, I will work on a quick demo for adding buttons to the ribbon.
I have updated the code to allow the button bar to be in the header, footer or body. (or multiple places too).