locked
Custom Workflow run as on-demand process -> no input parameters? RRS feed

  • Question

  • Hy all

    I've devolopped a Custom Workflow Assembly in Visual Studio 2010, which is triggerd by a process in crm 2011 (when creating or updating one of my custom entities). So all seems to work fine, I can extract the Target Entity (my changed/updated custom entity) out of the IWorkflowContext (Entity entity = (Entity)context.InputParameters["Target"] and create some child entities, based on this target entity.

    Now I want to be able to trigger this workflow also directly from my form (Run Workflow). So checked the "Available to run as an on-demand process" option and activated the process again. But when i trigger it over the Run Workflow Button on my form -> the plugin fails and after some investigations I found out the problem:

    - When run the process on-demand, the InputParameters-Collection is empty, so I cannot get the TargetEntity out of this collection and I don't know by which entity the workflow was triggered -> so it fails.

    What could be the problem? Why this difference between on-demand and automatically triggered workflow?

     

    Thanks for your help,

    Peter

    Tuesday, March 29, 2011 6:18 AM

Answers

All replies

  • This behaviour is as expected - the TargetEntiy is a representation of the data that was submitted that caused the workflow to fire, and so is not part of an on-demand execution. Instead you'll need to get the IExecutionContext.PrimaryEntityId as use this to Retrieve the entity data
    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Tuesday, March 29, 2011 6:29 AM
    Moderator
  • thanks for the answer. Now I understand the behaviour...


    Just one more question:

    - Is it possible to find out in code, what causes the workflow to trigger (on-demand or a change/newly created record)?

     

    Kind regards,

    Peter

    Tuesday, March 29, 2011 7:32 AM
  • I've not checked this, but it sounds like checking if the Target InputParameter exists or not would be an appropriate test
    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Tuesday, March 29, 2011 12:27 PM
    Moderator