0

I have a custom workflow action derived from SequenceActivity

  protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            var current = SPContext.Current;
            //current is null
         }

The code I copied is largely from another custom action, which is working as expected. I definitely missed something when copying things over and creating the new action, but I am not sure where to look.

2
  • There are normally 2 places to check: your Custom Activity and your .actions file. See my answer here stackoverflow.com/a/1257293/98933
    – Kit Menke
    Commented Aug 21, 2013 at 18:52
  • Kit, I checked out your suggestion. I added a Dependency prop for context and a parameter in the .actions file. The "Context" dependency property is null when I step into the action's Execute method. Could there be something I am missing higher up? Commented Aug 21, 2013 at 20:12

1 Answer 1

1

the problem your getting is correct and should be null ;) why? because workflow run under different thread to the current context ;) so instead of SPContext.Current you need to use WorkflowContext!

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflowactions.workflowcontext_properties.aspx

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflowactions.workflowcontext.aspx

public static DependencyProperty __ContextProperty = System.Workflow.ComponentModel.DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(YourActivityClass));

 [Description("Context")]
 [Category("Context")]
 [Browsable(true)]
 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
 public WorkflowContext __Context
 {
     get
     {
         return ((WorkflowContext)(base.GetValue(YourActivityClass.__ContextProperty)));
     }
     set
     {
         base.SetValue(YourActivityClass.__ContextProperty, value);
     }
 }

more details on the above code is here:

http://blogs.microsoft.co.il/blogs/davidbi/archive/2008/07/21/How-to-get-the-context-item-in-workflow-activity-sharepoint.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.