Help setting Data Field from Process XML Fields

  • 17 January 2009
  • 3 replies
  • 1 view

Badge +1

I’ve been trying to get Server Event code to read some XML data from a SharePoint Integrated Workflow and set a value back to a Data Field. I’m basically trying to get a value of a Document Library column and set a Data Field value. I’ve read through many samples on the Underground but none seem to be working for me. I keep getting “Object reference not set to an instance of an object” errors when I get to the Server Event Activity in question.


 


When I ran the SharePoint Workflow Integration Wizard the columns from the SharePoint Library where it was connected to were available to be in the K2 Object Browser under XML Fields > MyProcessName > MyProcessData > MetaData > Items > Item > [Complete list of list Library columns here]. I’m able to use the values in the object browser via the wizards (they work fine when dragged and dropped into an email activity for example).


 


Any guidance would be greatly appreciated. Below is an example of some of the code that isn’t working.


 


            XmlDocument xmlDoc = new XmlDocument();


 


            xmlDoc.LoadXml(K2.ProcessInstance.XmlFields["MyProcessData"].Value);


 


            XmlNode node = xmlDoc.SelectSingleNode("Items/Item/NameOfMySharePointColumn");


 


            String stingTest = node.InnerText;


 


            K2.ProcessInstance.DataFields["TestDataField"].Value = stringTest;


3 replies

Badge +6

Hi there,


What you are doing sounds quite correct and I can not see a problem with the code directly, but it sounds like you might have a problem with your XPath query. I would suggest you attach the debugger to the process to step through your code above (http://blog.mgallen.com/?p=153) , or if that does not work you can try the old-time workaround of saving the actual XML data field into a file or text string so that you can have a better look at the actual xml that it's trying to read.

Badge +2

try replacing:



 XmlNode node = xmlDoc.SelectSingleNode("Items/Item/NameOfMySharePointColumn");


with



XmlNode node = xmlDoc.DocumentElement.SelectSingleNode("Items/Item/NameOfMySharePointColumn");

Badge +9
I'd suggest either attaching to the debugger or spitting out debug lines around each call to figure out which field it is failing to find.  If you can narrow that down for us, I think we can be more helpful because looking at it now, it could be one of three things:  MyProcessData doesn't exist/spelled wrong, TestDataField doesn't exist/spelled wrong or the xpath isn't returning a node (which could be.

Reply