Welcome to MSDN Blogs Sign in | Join | Help

Developing Workflows in VS: Part 5 - Code Your Workflow

Step 3: Code Your Workflow

With your data in place, write your workflow logic.  It’s pretty straightforward, but here are a couple pitfalls that you should watch out for:

Pitfall: Re-using non-serializable SharePoint objects after rehydration
Many non-workflow specific SharePoint objects, like SPListItem, are not serializable, so when the workflow dehydrates, these items become invalid.  So if you try to use them when the workflow wakes up, you will get an error.  To avoid this, refetch items if you’re using them after a workflow rehydrates. 

Pitfall: Forgetting to make custom classes serializable
When creating your own class in a workflow, don’t forget to add the “Serializable” attribute to the class.  If you don’t do this and declare a variable of that class in the workflow’s scope, the workflow will fail when it tries to go to sleep and serialize the class.  If you notice that the workflow “completes” when it isn’t supposed to, this may be the culprit.

Pitfall: Updating locked items
If a document is open or locked, updating the item will throw an exception.  If you need a workflow to write to a column on the item, you can try to:  a) Have the workflow poll for the lock and executing the update only when the lock is released, or b) use item.SystemUpdate() to “burn through” the lock.  Note that for option (b), the user who has the document open will blow away the workflow’s changes if he saves the document.

FAQ: How do I set a custom status for my workflow?
The SharePoint SetState activity does this.  See WSS SDK for details.

 

Next time: Deploy and Debug Your Workflow

Thanks!
Eilene

Published Tuesday, November 28, 2006 9:00 AM by sptblog
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Sample Feedback Collection Workflow

Good morning Eilene,

Other people have mentioned that they'd like examples using aspx forms instead of InfoPath forms.

The Feedback Collection workflow in the Windows SharePoint Services V3 SDK is a great example that uses aspx forms, and works perfectly on MOSS, but when I implemented it on WSS V3.0 I got an error.

Everything works fine until I edit the task at which point I get the message: "Method not found: 'System.Guid Microsoft.SharePoint.Workflow.SPWorkflow.get_TemplateId()'" on TaskWFCT.aspx.

I haven't been able to debug it (although I have debugged the workflow itself and is fine up to this point). Could you let me know how to debug this page, which is the page used to edit the custom content type (as far I can make out)?

Would it also be possible to provide an example that does work on WSS v3.0?

This has been a great breakdown into developing workflows, but it would be incredibly useful to discuss the way to use aspx forms rather than InfoPath. There are many InfoPath examples out there, but aspx alternatives are scarce and the workflow development involves assimilating information from a variety of sources and hoping it will work!

Many thanks,

Kathryn

Thursday, November 30, 2006 4:24 AM by Kathryn

# PS Sample Feedback Collection Workflow

Sorry, I should have said that specifically, it would be really helpful if this example could be made to work on WSS v3.0. This is what I am trying to do, but I am struggling to debug it and also can't find a reference to get_TemplateId() either.

I'm going to keep looking at it, but your input would be much appreciated!

Many thanks,

Kathryn

Thursday, November 30, 2006 4:30 AM by Kathryn

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

Hi Kathryn, you're right, the API changed since the WSS kit was published, so I believe this should be AssociationId in the code. Funny thing is that I don't think it should have worked on MOSS either;).  We've fixed it for RTM.

In general, we have a lot more InfoPath solutions than aspx because we wanted to focus on the schedule implementation, and IP solutions are simpler to implement and understand.  However, the point I was hoping to convey in my Design/Bind Forms post was that there's only one extra step for aspx forms: the OM call.  All forms are aspx pages(as even IP solutions are just aspx pages that host an IP form).  The only real difference between the two is that IP forms call the workflow OM for you automatically, whereas the aspx forms require the developer to do this manually.  (well, deployment is a few extra steps too I suppose, but that's generc SharePoint feature/page deployment stuff).  Perhaps this needs another post;).  I'll see what I can put together.

Friday, December 01, 2006 3:53 AM by Eilene Hao

# OnePage Workflow in SharePoint 2007

OnePage : der einfache Blick auf das Wesentliche - die wichtigsten Informationen zu einem Thema auf einer

Tuesday, December 05, 2006 2:40 PM by SharePoint, SharePoint and stuff

# Creating Workflows with Visual Studio 2005 (Walkthrough)

Im not sure how many have found this yet but Eileen Hao has put together a Seven Part walkthrough with...

Thursday, December 07, 2006 12:25 PM by Bob Fox's Sharepoint Blog

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

Hi,

I had the same problem as Kathryn and I was able to debug when copying the DLLs of the TaskWorkflow project manually to the GAC and iisreset.

When I debug, I can see the TemplateFeatureId field in the fields list of the item, but I am not able to access this field using m_task["TemplateFeatureId"].

Currently I try to get the ID using List.TemplateFeatureId, but not it rans into the next exception "The association has no Parent List"

I am using WSS V3.

Any ideas?

Regards,

Benjamin

Tuesday, December 26, 2006 12:39 PM by Debugging

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

Hi Benjamin,

As Eilene Hao mentions, the API has changed and you need to change line 75 in WFInit.cs to:

GUID assocTemplateId = new Guid(Request.Params["AssociationID"]);

Karen, the reason that you thought there was a method get_TemplateId is that .NET properties are methods internally.  The method signatures include the word get but this is abstracted through language implementations by using the property, instead of a method for both the getter and the setter.

I still don't know why the library isn't getting updated in the GAC after a compile but I have a feeling that its' something to do with the versioning or VS.NET.  Try a Build>Clean Solution and Build>Rebuild Solution and see if that helps.  Copying the new DLL to the GAC fixes it but you might also check the installation batch.

Eilene,  where can we find the RTM starter kits and where are these InfoPath examples that you wrote about?

Many thanks!

Friday, December 29, 2006 5:47 PM by Thomas Goddard

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

As Eilene Hao mentions, the API has changed and you need to change line 75 in WFInit.cs to:

GUID assocTemplateId = new Guid(Request.Params["AssociationID"]);

^^ Anyone got it working with this one ? In my case WFInit doesn't work with this code :S

Tuesday, January 09, 2007 1:15 PM by Armand Hejhoe

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

As Eilene Hao mentions, the API has changed and you need to change line 75 in WFInit.cs to:

GUID assocTemplateId = new Guid(Request.Params["AssociationID"]);

^^ This is a joke.

You have to change line:

assocTemplate = wtc[workflow.TemplateId];

with this one:

assocTemplate = wtc[workflow.AssociationId];

Have an ice day

Wednesday, January 10, 2007 4:44 AM by Edo Civic

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

Hi Eileen

I am not able to make this work either.

Even though I changed to 'AssociationID' in the code I still get the same error when trying to run the Collect Feedback workflow.

And I would also like to know where I can find the RTM starter kit for WSS 3.0

Tuesday, January 16, 2007 6:20 AM by Woody

# Updating properties of SPFileVersion objects

while accessing the older versions of the file using SPFileVersionCollection Object , we need to edit a property of all the older versions.

These changes in the properties are not visible in the Version History of that file.

The code we write for this is as :--

SPFileVersionCollection vv = file.Versions;

foreach (SPFileVersion fv in vv)

{

  if (!fv.IsCurrentVersion)

  {

   fv.Properties["DLC State"]="Superseded";

   fv.File.Item.SystemUpdate(true);

  }

}

Can anybody give a proper solution please.

Saturday, January 20, 2007 5:15 AM by kuldeep

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

How can I get the user who started the workflow, or who execute a certain step? In my approval workflow, I want to know who approved the item in document library.

Sunday, February 04, 2007 10:44 PM by Zhang Mingquan

# Start Learning Workflows!!

Wow such an exciting topic to learn!! its nice and fun yet its a bit difficult to grasp easily,,, This

Thursday, April 12, 2007 9:46 AM by Code Eater

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

I got it!

You need to modify line 81 in TaskWFCT.cs, not line 75 in WFInit.cs. Change it as:

assocTemplate = wtc[workflow.AssociationId];

And don't do anything to other programs!

Then, you need to right click on the TaskWorkflowContentType project, click Rebuild, and then you run installall.bat, and everything will be ok!

Tuesday, May 29, 2007 6:19 AM by fengerzh

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

Hi eline

thanks for the wonderful demo of workflow.

i am getting an error when i attach the workflow to the document library.

unknown error

Troubleshoot issues with windows sharepoint services

when i publish the infopath form i followed the same steps which were mentioned in your demo.

is there any settings to be made to the central admin before this

with regards

Srividya S

Thursday, July 05, 2007 8:01 AM by srividya s

# 2007 MOSS Resource Links (Microsoft Office SharePoint Server)

2007 MOSS Resource Links (Microsoft Office SharePoint Server) Here is an assortment of various 2007 Microsoft

Wednesday, September 12, 2007 11:14 AM by The Boiler Room - Mark Kruger, Microsoft SharePoint MVP

# Unknown error..

I am facing the error while copying the documents from sharepoint server 2003 to microsoft sharepoint server 2007. The problem is after copying the documents to MOSS 2007, when i check for version history, i m getting the unknown erro.. could anyone help me out in resolving this issue..

thanks in advance..

Saturday, September 15, 2007 10:30 AM by sandy

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

hi,Edo Civic

i have the sdk sample of Sample Feedback Collection Workflow. so can u please explain how to make it as work in sharepoint.

i tried to make it as work. but in share point site iam getting file not found error.

and the page iam getting is http://son2034/_layouts/WFAssoc.aspx?List={533CC181-017F-4BB1-9E8F-8EE00F502CA4}.

can u please explain how to do step by step procedure to make it as work.is there any modification i have to do in that solution.

please give me reply as early as possible.

Regards.

sapthagiri

Tuesday, September 25, 2007 3:39 AM by sapthagiri

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

I m assign to implement and customized during my intership a system of workflow on MOSS & VS.net 2005. really I do not understand that subject. my lecturer told me that it is a sort of generic workflow system; not a specific workflow.

How can I build a generic system of workflow? please give me some suggestions and guidencies.

I thaught he saying I should build a particular one by using the formers DEK.

sincerely Paul...

Wednesday, December 12, 2007 11:09 AM by Paul ASSIENE

# Collect FeedBack Workflow

Hi,

  There is some problem eith the collect feedback workflow in the ecm starterkit samples.

When i am running the bat files in the collect feedback workflow,it is installed and iam able to see the sample:Collect feedback work on the workflow templates.

               I am selecting the options like start the workflow when a nwe item gets added then when i click next i am able to see the WFAssoc.aspx page and i am giving the reviewers name  and clicking ok .

but when ia m uploading the document in to the document library workflow is not starting,i am not able to understand.

can any one help?

Thanks in advance

Friday, January 04, 2008 1:40 AM by chandrika

# SharePoint resources

Gracias a Mark Kruger (SharePoint MVP) por esta lista de recursos de SharePoint donde podréis encontrar

Monday, February 18, 2008 10:21 AM by SharePoint mola

# SharePoint resources

Gracias a Mark Kruger (SharePoint MVP) por esta lista de recursos de SharePoint donde podréis encontrar

Monday, February 18, 2008 11:09 AM by SHAREPOINTBlogs.com Mirror

# re: Developing Workflows in VS: Part 5 - Code Your Workflow

Too bad one of the worst offenders of the "forgetting to make custom classes serializable" is Microsoft's own Enterprise Library 3.1 (May 2007) edition.  Want to use the El3 Logging Block in a SharePoint custom workflow?  Sorry, the logger in EL3 isn't serializable.  Same is true for trying to use EL3's Exception handling block.  Seems the Microsoft left hand isn't talking to the right hand.  What a shame.

Friday, March 07, 2008 9:52 PM by Fred Morrison

# Thanks to Lexis Nexis!

We are about to start a great day showing technologies like .NET 3.5, Visual Studio 2008, and SharePoint

Wednesday, April 30, 2008 7:40 AM by Kirk Allen Evans's Blog

# Problem on edit SPFile properties from a workflow.

Hi,

I've tried to create simple sequential workflow in VS 2008. Everything works fine except I can't edit any property of the SPFile from the workflow. No exceptions fired, no messages in a log.

There was the same question related to the SPFile versions, but the problem seems to be more common.

Are there any ideas what the problem could be. Thanks much!

Yuriy.

Monday, June 09, 2008 4:52 AM by yfrolov

# 应用SharePoint的Workflow须记住的10句话!

1)SharePoint的工作流是基于文档的工作流,只能关联到列表,文档库和内容类型上 2)SharePoint的工作流模板利用网站功能(Feature)来发布 3)SharePoint的...

Tuesday, September 23, 2008 11:13 PM by 晃晃悠悠

# 微软sharepoint产品组博客——使用VS进行工作流开发系列博客

最近的两个月一直在研究SharePoint的内容,从配置到开发,从配置,到sharepoint对象模型,webpart,eventhandler,workflow,contenttype,自定义字段...

Monday, November 24, 2008 12:35 AM by virus

# 使用VS进行工作流开发系列博客6-Developing Workflows in VS: Part 5 - Code Your Workflow

在VS中开发工作流:编码你的工作流原文地址:http://blogs.msdn.com/sharepoint/archive/2006/11/28/developing-workflows-in-vs...

Monday, November 24, 2008 9:23 PM by virus

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker