Fire Workflow from a Plugin On Event Open Form RRS feed

  • Question

  • I am looking for some help on how I can fire a workflow from a plugin and how this can be done on a "Form On Load" event.

    Currently I have some Java Script, that is fired on the Form On Load. The java script fires a custom workflow, which creates a custom Audit Record for us. This allows managers to see which staff members are opening which accounts. We cant use the security profiles or teams as accounts have mulitple owners which vary from account to account. The current process works absoultly fine.


    We are currently in the cloud on CRM 2011, and in a couple of months we will be updating to CRM 2013. Our initial UAT testing show our current Java Script will no longer work. A suggestion was made to use a plugin instead of the java script, as this will ensure greater compatibility going forward with an future updates.

    Thanks in advance


    Wednesday, October 16, 2013 8:37 AM

All replies

  • Hi Graham,

    Initially JS codes were not supported in MS CRM 2011 online refresh UI. Now for CRM 2013 online it is supported.

    Still if you want to modify your code, here are the options you can use.

    1. You can use oData Service calls in onload function to create Audit(Custom Entity) record in CRM

    2. You can update a field (custom field. preferrably boolean) from your Javascript code on load. Write a workflow which triggers on update of the field. You can use your custom workflow there to create Audit Record



    Wednesday, October 16, 2013 10:19 AM
  • Hi Graham,

    You can use the new Actions feature in crm 2013:


    You can fire it from JavaScript, and works similar to a workflow. It also has its own message name if you need to write plugin code for your requirement.



    Wednesday, October 16, 2013 10:22 AM
  • Hi.

    Since the purpose of your code is to audit user access "This allows managers to see which staff members are opening which accounts".

    I am afraid using plugin will be a very expensive process since it will have to be fired on "execute" message to create custom audit record on page access which is not recommended.

    Though JavaScript approach is also quite expensive since it will require a web service access as well.

    I do believe the best approach should be using the out-of-box security model, team, and record share.


    Wednesday, October 16, 2013 10:52 AM
  • Thank you for the reply Jamie,

    However the out-of-box security model is fairly limited and is no where our needs.

    For example we could have an account ABC ltd. Which is a financial company. For Pensions business it is looked after our Pensions North Team, for Investments it is looked after our Investments Top Accounts Team, Protection is looked after our Protection North team. and so on. The teams can be made up of one or two people. Account DCF ltf could have the same Pensions and Investment team as ABC ltd with a different Protection and General Insurance team. We have around 40,000 accounts. We also wanted to allow all users to see all accounts as they oftern covered for each other.

    Our Javascript fired a workflow upon Load. The workflow created a Custom Record called Record Audits. The record contained, The firm that was opened, data and time, the various teams (as above) associated with the account and the user who had fired the workflow (opened the account)

    Dynamics Auditing or security does not allow you to easily if at all extract this information. As we have it a custom entity our managers could take a download and with a quick pivot identify which accounts where being viewed, any accounts with a high view from someone not on one of the original teams would lead to a general conversation to find out the reasonings. Our issue is we store a lot of Sales data with the records and it is a risk some looking up all our biggest Accounts and leaving with that information. Yes they could still do that, but with regular checks means they could not get much.

    The original Java Script to fire the workflow was used from one of these forums and took only an hour or so to set up. It has worked a treat for a year, until now!

    Wednesday, October 16, 2013 2:56 PM
  • Hi Graham,

    As Adam mentioned, the all-new Actions coming up on CRM 2013 is the best solution, if you want to do everything within the CRM territory.

    You might also consider writing a plugin for the "Retrieve" message of Account, so it gets fired whenever account records are read. In which case, obviously, you got to filter-out non-interactive reads.


    Thursday, October 17, 2013 3:23 AM