Archives

Opening SharePoint Links in a new windowUse SHIFT+ENTER to open the menu (new window).
Mail Enabled Lists vs. The Missing Windows 2008 POP3/IMAP Server Use SHIFT+ENTER to open the menu (new window).
7 Tools for SharePoint DevelopersUse SHIFT+ENTER to open the menu (new window).
Public Facing Masterpage TechniquesUse SHIFT+ENTER to open the menu (new window).
How to Quickly Deploy and Activate a Timer Service to Your Site CollectionUse SHIFT+ENTER to open the menu (new window).
Custom SharePoint Master Page Feature with WSP BuilderUse SHIFT+ENTER to open the menu (new window).
Date Math with InfoPathUse SHIFT+ENTER to open the menu (new window).
Enterprise Search Tricks and Tips Part 1Use SHIFT+ENTER to open the menu (new window).
Populating Word Documents With SharePoint Data. Try The DIP!Use SHIFT+ENTER to open the menu (new window).
Programmatic Deep Dive into Blank SharePoint Lookup ColumnsUse SHIFT+ENTER to open the menu (new window).
SPQuery Hacks Part 1: InfoPathUse SHIFT+ENTER to open the menu (new window).
Adventures in Excel Services 2010Use SHIFT+ENTER to open the menu (new window).
What Is The Easiest Way To Mess Up SharePoint? Use SHIFT+ENTER to open the menu (new window).
Redirect SharePoint Navigation - NYC SDUG Quick DipUse SHIFT+ENTER to open the menu (new window).
SPQuery Hacks Part 2: WorkflowsUse SHIFT+ENTER to open the menu (new window).
Upgrading SharePoint 2007 RTM to SharePoint 2010 Use SHIFT+ENTER to open the menu (new window).
Using JQuery to add charts to your Data ViewsUse SHIFT+ENTER to open the menu (new window).
Quick Rundown: Multi-line Text ColumnsUse SHIFT+ENTER to open the menu (new window).
Document Previews Won’t Open In FAST Search Using HTTPSUse SHIFT+ENTER to open the menu (new window).
Sleazy Reporting: SharePoint 2010 ListsUse SHIFT+ENTER to open the menu (new window).
Helpful Debugging with SharePoint C Sharp CodeUse SHIFT+ENTER to open the menu (new window).
Configuring Remote Blob Storage in SharePoint 2010Use SHIFT+ENTER to open the menu (new window).
Getting E-mail to Work in Your SharePoint 2010 Dev EnvironmentUse SHIFT+ENTER to open the menu (new window).
Sleazy Reporting: SharePoint 2010 External Content TypesUse SHIFT+ENTER to open the menu (new window).
Programmatically Dealing With Potential Multi-Select ColumnsUse SHIFT+ENTER to open the menu (new window).
SPQuery Hacks Part 1: InfoPath
By: Christian Holslin
 

Have you ever created a custom Workflow with Visual Studio which triggers off a change from an InfoPath Form?  Have you ever ran into the situation where your Workflow seems to end up with the old InfoPath Form values after the Form has been resubmitted to the SharePoint Form Library?  On a recent project we discovered this particular issue was happening on a SharePoint site which was patched with the latest Cumulative Updates released after Service Pack 2.  While this issue did not appear in the vanilla Service Pack 2 version of SharePoint Server 2007 (running on Windows Server 2003 with SQL Server 2005), we did find ourselves working towards a fix for our client's patched environment.  What did we do?  We turned to the SPQuery object for help.  This article is the first in our SPQuery Hacks series.

Winning the Race Conditions

In general, the SPQuery object is a great and efficient way (albeit more advanced way) of selecting a single item from a SharePoint list or library when you don't have an ID.  In our case, we have the ID already, but we just needed to get the latest value from a simple text column as it switched from one value to another when the user edited the associated InfoPath Form.  The Workflow infrastructure was returning the old values causing our Workflow to stop running because it didn't detect the change from the user.  This is how we solved the problem:

Fetch the Same Item Again

Instead of using SPWorkflowActivationProperties.Item to read values from the Form's promoted properties, we used an SPQuery to get a second instance of the SPListItem which represented our InfoPath Form using the code snippet below:

// First: Open new SPSite and new SPWeb with using statements

// Then: Fetch a new SPList reference as list with the code below

 

// Be safe: get the internal name of the built-in ID column

string idInternalName = list.Fields["ID"].InternalName;

 

// Get the ID of your item from the Workflow properties

int id = workflowProperties.ItemId;

 

// Construct a new SPQuery object and write the CAML

SPQuery query = new SPQuery();

query.Query = "<Where><Eq><FieldRef Name='" + idInternalName + "' /><Value Type='Text'>" + id + "</Value></Eq></Where>";

 

// Run the SPQuery against your new SPList reference

SPListItemCollection itemCol = list.GetItems(query);

 

// Your new SPListItem reference!

SPListItem item = itemCol[0];

 

Use the New SPListItem Reference

After getting your new object reference (remember, this is actually the same item your Workflow is already running on), use this object instance to populate your serializable Workflow class variables to use in the remaining Workflow activities:

this._status = (string)item["Status"]; // Replace "Status" with your field

While this all seems a bit overkill for fetching one little string value, it does the trick and your Workflow can continue running using the latest value promoted from the InfoPath Form to make the right decisions as it executes.

--Christian Holslin

        

Comments

There are no comments yet for this post.
Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Your Name *


e-mail address *


Website (optional)


Comment *


Attachments

 Subscribe

  GigWerks RSS  Gig Werks Mailing List 

 Contact Us

 Connect

 Resources

  SharePoint Resources
  Business Intelligence Resources
  Upcoming Webinars



©2009 Gig Werks. All rights reserved. Privacy Policy