CRM 2011 Custom Button on Custom Entity to trigger Workflow through JavaScript

I will provide detailed step on what I did to do this. The objective of my example is to have a custom button 'Create Opportunity' on my custom entity that triggers a workflow to create an Opportunity. This way the users don't have to click 'Run Workflow' and choose which workflow they want to run. You can also alter the JavaScript to do other stuff as well.

There are three places where we should put the button mainly:
1. Custom Entity Form

2. Homepage Grid

3. Sub Grid

1. In order to inspect the correct sequence number of where the button will be placed on each section, you can first run the tool provided from the sdk \sdk\samplecode\cs\client\ribbon\exportribbonxml. Just modify the exportribbonxml.cs to only generate the entity you are interested in:

Run the tool program, specify your server connection and it should give you the XML in the output folder with the name Ribbon.xml.

Open the xml, search for the sections and write down the sequence numbers of where you want to put them in. In this case I want to put it after 'Start Dialog' button:

Sequence is 25, 50, 40

2. Export your solution with the custom entity you want. Open the customisations.xml and inside the RibbonDiffXml tag, specify all the contents of the child tags that describe the rules, custom actions, commands, etc. (Look at the SDK for more information). This is the section that I wrote:

3. For the JavaScript that triggers the workflow, there is a post that describes how to do that here and I just make use of that. The CRM Parameter passed from the above is iterated and the workflow is triggered for each of the selection.

Hope this helps :)


CRM 2011 Javascript Functions

Starting to use CRM 2011, here are some useful javascript reference (this list will get longer and longer as time goes):

Hide/Show Field

Hide/Show Field but removing white space

Disable/Not Disable Field

Set Requirement Level

Set Required Level

Validate Number Field and Character Limit

Validate Future DateTime

Example function to hide left navigation item based on a condition

Avoiding the checkbox OnChange bug so that it fires off immediately (put this in OnLoad event of the form)

Set Lookup Value
Hide Picklist Item Text