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 SPWorkflow object and I want to check if this workflow is running. It's a Sandbox solution so I don't have access to SPWorkflow.SPWorkflowStatus.

I have tried the following:

if (workflow.InternalState != SPWorkflowState.Running)
{
     // the workflow is not running
}

but what I get in workflow.InternalState is a list of SPWorkflowState enum values: "Running" and "NotStarted". This doesn't make any sense to me.

It should be a pretty simple thing but just can't get it to work.

Does anyone have the solution to this?

share|improve this question
add comment

2 Answers 2

The workflow is acting on an item (sometimes called a context item) -- you can get its GUID from workflow.ItemGuid. Then, you can check the workflow status from one of its fields, as eirikb said.

Once you have the SPListItem, you can then query its properties to get the workflow status number.

Here is a blog post about this, but for completeness, here's some untested, on-the-fly code for you:

var parentList = workflow.ParentList;
var listItem = parentList.GetItemByUniqueId(workflow.ItemGuid);
var workflowStatus = listItem[list.WorkflowAssociations[workflow.AssociationId].Name]);

workflowStatus should be a positive int -- it's an enumeration value whose friendly name is outlined on the like eirikb noted. Again, for completeness, here it is.

share|improve this answer
add comment

There should be a column on your list with the same name as the workflow association.
This column should contain a number which represents a status of your workflow. So if this column is set to 2 then your workflow is running.

share|improve this answer
    
As it's a sandbox solution I don't have access to SPWorkflowStatus link –  Høgsdal Nov 2 '12 at 4:22
    
The column I'm talking about is on the item, you should have access to it. –  eirikb Nov 2 '12 at 6:13
    
If the item is the workflow I can't see that value on the item. –  Høgsdal Nov 8 '12 at 3:12
add comment

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.