<

Go Premium for a chance to win a PS4. Enter to Win

x

SharePoint 3-State Workflow Trap

Published on
9,626 Points
3,426 Views
2 Endorsements
Last Modified:
I used to be SharePoint evangelist in our company, so my Outlook always full of questions about how to do this, or where I can find that. One day I found such an email with the following question: "how to attach 3-State workflow (one of the workflows available "Out-of-the-Box") to the Wiki Library".

Looks like a good idea for business users, especially if they need to control wiki content contribution. I have to mention that their department use small isolated SharePoint farm based on MOSS 2007 Standard.

As usual, I sent her simple step-by-step manual from the MS TechNet (or someone’s blog article, I don't remember the exact source).

She has successfully attached workflow to the library, assigned column with state values, and managed to start the workflow without any problems. Although all the workflow instances she started have never been finished successfully. That became interesting for me so I visited her servers myself. After some diving into logs I found the following exception:

System.ArgumentException: Value does not fall within the expected range.     
at Microsoft.SharePoint.SPFieldCollection.GetField(String strName, Boolean bThrowException)     
at Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException)     
at Microsoft.SharePoint.SPListItem.GetValue(String strName)     
at Microsoft.SharePoint.SPListItem.get_Title()     
at Microsoft.SharePoint.Workflow.Application.IssueTracking.OnWorkflowActivated(Object sender, EventArgs e)    
at System.Workflow.ComponentModel.Activity.RaiseGenericEvent[T](DependencyProperty dependencyEvent, Object sender, T e)     
at System.Workflow.Activities.HandleExternalEventActivity.RaiseEvent(Object[] args)     
at System.Workflow.Activities.HandleExternalEventActivity.Execute(ActivityExecutionContext executionContext)     
at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)     
at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext)     
at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)     
at System.Workflow.Runtime.Scheduler.Run()

Open in new window

Well, let's see...
Looks like Microsoft.SharePoint.SPListItem.get_Title()  is a root of evil. I opened SharePoint DLL with a Reflector (pretty useful tool, especially for SharePoint specialist) and found the following code:
 
public string get_Title()
{
    object obj2 = this.GetValue("Title");
    if (obj2 != null)
    {
        return (string) obj2;
    }
    return string.Empty;
}

Open in new window


Gotcha! There is no "Title" column in a default Wiki template. And reference to this column is perfectly hardcoded to the 3-State workflow code. Actually not sure why. Thus we just added a new column with this name and now it works well... Although we never assign any value to that field, you probably want to set something more meaningful, so you can create Title field as calculated and use formula to grab page name or any existing data.

At least she hasn’t contacted me again on this :)

PS : Please note that you can meet the same issue when you try to attach OOTB 3-State workflow to the Library with no "Title" column!

Hope you find this Article helpful - and dont forget to vote :)
2
Comment
0 Comments

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Join & Write a Comment

Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month