<

Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

SharePoint 3-State Workflow Trap

Published on
9,588 Points
3,388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
0 Comments

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month