Welcome to Office Zealot Sign in | Join | Help

Julie's Office Dev Blog

Sorta like yoga... just less flexible.
Custom Workflows With Office System Server 2007

It hasn't been the easiest thing to figure out but I'm awfully happy to say that I've finally got a near fully functional complete custom workflow via Visual Studio 2005.  One of the key points to remember is that “Nothing Is Magic” with this thing.  There are a few issues in doing this workflow development that hopefully are my pure ignorance (and/or lack of documentation). 

Deployment of these workflows isn't the easiest thing.  It has taken me awhile of editing the default “Install.BAT” and trial and error to actually get the workflow (once customized beyond the HelloWordSequential example) installed correctly with everything in all the right places.  It also appears that I have to reinitiate the workflow after every build.  I foresee this being a huge problem in production.  I am hopeful that I'm simply missing something but if I tag a library with my workflow and call it “My Righteous Workflow.”  I make a change to the workflow, rebuild, run install.bat to update everything.  My original “My Righteous Workflow” doesn't work and, morever, doesn't update.  I have found I have to remove the first instance of the workflow and the retag the library with the new instance of the workflow.  Or I can disable new instances of the old workflow and add the workflow again.  I can see this getting a little hairy with scope creep.  We all know that you start one project and 5 months later it's a monster the likes of which you never imagined.

One of my largest problems was actually updating the initial list item.  Essentially I created a Form Library list.  I created an InfoPath form (running in the web browser, of course) as my content type.  The initial content type requires a few pieces of information.  Once the new item is created, the workflow is automatically kicked off.  Two new tasks are created asking two separate individuals for additional information (using Infopath forms again).  Once they've submitted the data, the original list item needs to get updated with that data.  It's really pretty easy but I guess I was thinking that the workflowProperties object has the Item in it and that I could just update that Item but you can't.  You actually have to tag the item manually and run the update method on it.  The workflowProperties object gives you everything you need in order to do this very easily:

SPWeb thisWeb = new SPSite(workflowProperties.SiteId).OpenWeb(workflowProperties.WebId);
SPListItem thisItem = thisWeb.Lists[workflowProperties.ListId].GetItemById(workflowProperties.ItemId);
thisItem.Properties["myFirstProperty"] = netTaskAfterProperties.ExtendedProperties["firstProperty"];
thisItem.Properties["mySecondProperty"] = netTaskAfterProperties.ExtendedProperties["secondProperty"];
thisItem.Properties["myThirdProperty"] = netTaskAfterProperties.ExtendedProperties["thirdProperty"];
thisItem.Update();

Using InfoPath forms for each stage of your workflow is pretty easy too.  You simply create the InfoPath form, add it to your workflow.xml file and then make sure you set the TaskType property accordingly for each stage.  Stages can share InfoPath forms too.

Here's an excerpt from my workflow.xml file:

<MetaData>
<Task0_FormURN>urn:schemas-microsoft-com:office:infopath:New-Hire-Office-Manager-Initiation:-myXSD-2006-05-26T17-29-20</Task0_FormURN>
  <Task1_FormURN>urn:schemas-microsoft-com:office:infopath:NewHireCommInitiation:-myXSD-2006-05-26T17-29-20</Task1_FormURN>
  <Task2_FormURN>urn:schemas-microsoft-com:office:infopath:NewHireNetworkInitiation:-myXSD-2006-05-26T17-29-20</Task2_FormURN>
  <Task3_FormURN>urn:schemas-microsoft-com:office:infopath:NewHireCompletionTask:-myXSD-2006-05-26T17-29-20</Task3_FormURN>
  <Task4_FormURN>urn:schemas-microsoft-com:office:infopath:NewHireBillingInitiation:-myXSD-2006-05-26T17-29-20</Task4_FormURN>
  <Task5_FormURN>urn:schemas-microsoft-com:office:infopath:NewHireSendBillingTask:-myXSD-2006-05-26T17-29-20</Task5_FormURN>
....
</MetaData>

I actually have a lot of tasks in my workflow at the moment but a few of those tasks use the same form and as a result I set the task properties TaskType for each of those tasks to the same number as so:

myFirstTaskID = Guid.NewGuid();
myFirstTaskProperties.TaskType = 0;
.... myFifthTaskID = Guid.NewGuid(); myFifthTaskProperties.TaskType = 4; mySixthTaskID = Guid.NewGuid(); mySixthTaskProperties.TaskType = 4;
mySeventhTaskID = Guid.NewGuid();
mySeventhTaskProperties.TaskType = 5;

Clearly these variable names are for purposes of this post but I hope you get the picture.  It's also very easy to pass data into those InfoPath forms.  Here I have passed in the value of the “Floor“ column from the original list item into one of my InfoPath task forms.

myFirstTaskProperties.ExtendedProperties["Floor"] = workflowProperties.Item.Properties["Floor"];

The other half of this task is to create an ItemMetadata.xml file containing the fields you will be passing in and using it as a data connection in the InfoPath form.

I hope this post sheds some light on how to get custom workflows moving... it's quite an exciting feature.  I'm hoping there is an easier method for deploying from your dev environment to a production or staging environment ...

Posted: Friday, June 16, 2006 2:40 PM by jkremer

Comments

bsandeman said:

Hi Julie,
I wonder if you might be able to give me some advice.
From your latest post it looks like you have got what I need working...

I am trying to trigger a workflow automatically when an xml doc is created in a sharepoint library. This workflow then creates a task and has an infopath form associated with it. Ideally this form will display data from the xml document, but I'm not worrying about that yet... As I cannot get the workflow to even start, as I get an error saying "Value cannot be null".
Could you possibly give me some advice on this, or maybe even send me an example of how to make it work?

thanks very much
cheers
Bruce
bruceATdeltascheme.com_nospam
# June 20, 2006 4:10 AM

Anonymous said:

Out of curiousity, did you have to set a 'TaskListContentTypeId' in your workflow.xml file? I did - but I've not found much mention of it anywhere. I was wondering if it was just me!
# June 20, 2006 5:22 AM

Anonymous said:

Hi Bruce,

I will email you as well... I had that problem initially when I first began with this platform. I have no idea what it is but essentially I had to take my workflow down to just the activated routine and rebuild it. I have discovered a few things I'll post and email you about that it may have to do with though.

Andy, no, I have not had to do that...
# June 25, 2006 3:03 PM

Anonymous said:

How exactly did you get the form associated with the task? I've been through like 10 tutorials and a million forums but to no avail :( I'd appreciate any help.

Thanks,
Mike
# July 5, 2006 9:50 AM

Anonymous said:

I got it associated but it can't find the form, how and where do you deploy this form? I tried installing the form with features but it still doesn't pick it up...
# July 5, 2006 11:51 AM

Anonymous said:

Hi Michael,

You deploy the form via the Install.bat. Are you using the Sharepoint template from the ECM starter kit?
# July 10, 2006 11:05 AM

Anonymous said:

I am having having difficulty associating an InfoPath form with a task. I have followed the 7 Development Projects with the Microsoft Office System and Windows SharePoint Services 2007. Can you elaborate on your current install? I have loaded all the latest Beta's that I can find today.
# July 10, 2006 1:12 PM

Anonymous said:

Chris, I'd problems with that, and how I ended up doing it was different to the '7 development projects' thing. I've posted about this on my blog - http://www.neodynium.com/display.php?id=267 - see the section on 'Attach your Infopath forms'

Michael, actually, the same post above mentions the deploying of the infopath forms. Essentially, you need to reference their locations in the 'features.xml' file
# July 10, 2006 2:56 PM

Anonymous said:

Have you tried creating the multiple tasks in different task lists? For instance, one task gets created in Task List A another task gets created in Task List B....

I can see how you managed to assign different task forms to different tasks. But I'm wondering if there is a way to create tasks in multiple Task Lists.

Thanks
Brad
# July 12, 2006 11:45 AM

Anonymous said:

Hi Julie, I just face the same problem as bruce does. Could you pls email the stuff to me as well.

I would greatly appreciate that.

Thanks a ton!
Vin
# August 29, 2006 1:08 PM

Anonymous said:

Hi Julie,

As told you before, ma still working on the Workflow and couldn't figure out exactly how to go abt it. I would appreciate if you could send me the code snippet that you send it to bruce.

Thanks in Advance

Vin
era_ruler@yahoo.com
# October 26, 2006 10:18 AM

Anonymous said:

This seemed to work for me although the item.properties[""] did not.

SPListItem thisItem = workflowProperties.Item;
thisItem["Department Approval"] = Status;
thisItem["Department Approved By"] = taskProps.AssignedTo;
thisItem["Department Comment"] = Comments;
thisItem["Department Decision Date"] = DateTime.Now.ToString();
thisItem.Update();
# October 31, 2006 11:03 AM

Anonymous said:

Hi all,

As a last resort, I am posting this question to you all in hopes that you have an answer for me regarding MOSS 2007, Worklfows, and SharePoint Designer. I've been looking and posting in MSDN newgroups but have had no luck. And you all seem to no this stuff pretty well.

I have a reqt to build 1 large but easy workflow. I have an InfoPath form that the user will populate from a Forms Library where this form is the template for the library. The form needs to be routed and approved by one member of each group. Thats it.

My workflow needs to start off by checking a few of the values the user has chosen on the form and then chooses the appropriate path of preset user groups to send it to for approval.

Basically a simple IF statement with a bunch of If/Else's.

I have been able to create workflows using the internal Approval Process that comes with MOSS, but it doesn't allow me to do any IF conditional statments. I also have tried the next step by using Sharepoint Designer, but I can't figure out how to do the Approval part. This is where you all come in.

I can create the IF statements easy enough, but the Actions to have them take is where I am lost. I don't see Actions that performs the Approval routing type of thing that exists in the internal workflow template of MOSS. Am I missing something or misunderstanding one of them?

Otherwise, can someone point to examples for creating the workflow in VisualStudio05 that work with a Form Library and Infopath?

Thanks,
Jeff

# December 7, 2006 12:12 PM
Anonymous comments are disabled