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;