locked
How to detect workflow trigger event within a custom workflow? RRS feed

  • Question

  • I have a custom workflow which is triggered on the update of several attributes.

    When the workflow executes I would like to know which of the various attributes has actually triggered it, so I can write out a helpful message to an audit trail. 

    I would have expected to see the trigger field name in the workflow context. I can see a property in the SharedVariables property bag called 'TriggerAttribute'. However, the value of this property shows the name of a different attribute to the one that has changed.

    For example, if I trigger the WF by changing the value of the attribute 'name' the TriggerAttribute field contains the name of my 'start date' attribute which I did not update.

    Have I missed something obvious here?
    Bill
    Monday, September 21, 2009 5:37 AM

Answers

All replies

  • Unfortunately I don't think this is exposed in the workflow. I'd suggest writing an asynchronous plugin instead, as this will allow you to identify the attributes that have been modified
    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Monday, October 26, 2009 2:48 PM
    Moderator
  • Thanks for confirming my suspicions.

    Actually, in this case, the benefit of using a custom workflow over an async plug-in outweighs this limitation, but thanks for the suggestion.


    Bill
    Monday, October 26, 2009 3:36 PM
  • For example, if I trigger the WF by changing the value of the attribute 'name' the TriggerAttribute field contains the name of my 'start date' attribute which I did not update.

    Are you sure you didn't ForceSubmit that attribute?  I find it highly suspicious that a conspicuously named member like TriggerAttribute would exist and also report wildly inappropriate data.  I could, however, understand if it only has room for a single name as I would expect the Workflow engine to shortcut the evaluation of modified attributes to simply the first that matched.  However, that assumes that you have your "start date" attribute as a trigger for the Workflow.  If that assumption is correct, what happens if you remove it from the Workflow's trigger list?
    Dave Berry
    Monday, October 26, 2009 5:10 PM
    Moderator
  • You can see the original data in IWorkflowContext.InputParameters. InputParameters["Target"] will contain the data that you are looking for.
    Wednesday, October 28, 2009 9:43 PM