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

THE STEPS:
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 :)

Andreas

Comments

  1. Thanks for posting this, it really helped.

    One note is, that in the opening attributes in the XML it's changed to lowercase.

    ReplyDelete
  2. Hi
    Thanks for the great post
    I've done every think like you have done
    When i call the java script function it gives me 2 thumbs up Success (the Success Alert!) but there is no workflows fired up !
    I even don't know how to trace it !
    funny thing is that it seems that every thing is seems to be alright, but no workflow expansions !

    so what should i do?



    ReplyDelete
    Replies
    1. Well couple of things you can do:
      1. Make sure your workflow id is correct and workflow is published and at organizational level.
      2. Check if Async processing service is running.
      3. Enable tracing (look up on msdn) on the server so that it produces trace logs.
      4. If your workflow runs it should be shown in System Jobs record.

      HTH,
      Andreas

      Delete

Post a Comment

Popular posts from this blog

SharePoint 2013 anonymous access add attachments to list item

CRM Plugin - Parent and Child Pipeline

Sitecore custom publish agent from specific node and at a specific time