Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
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 Aug 21 '13 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? –  SharepointHater Aug 21 '13 at 20:12

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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