Skip to main content

Can anyone please offer some advice on accessing datafields from within a workflow? I have a an XML field showing in the object browser as 'firstname', which is populated from an InfoPath form. Once the workflow has been approved I want to take this name along with some other information and use it to create a user account. To do this I have added a Default Server Event (Code) activity and gone to View Code -> Destination Rule. Then under the ExecuteCode method I am trying to read from the firstname field with:


user = K2.ProcessInstance.DataFields["firstname"].Value.ToString();


 But this gives the following exception:


28006 Datafield firstname not found


 I have tried using ActivityInstance instead and get the same exception. Am I going about this completely wrong, and are XML datafields accessed in a different manner?


 Thanks. 


 

OK I guess I should be using something like the following:


user = K2.ProcessInstance.XmlFields[

"firstname"].Value.ToString();


 Although that still gives an exception:


 28031 Xmlfield firstname not found


Is firstname truly an XML data field, or is it a field inside of an InfoPath form?  If it's in an InfoPath form, there will be a process-level XML field containing the entire XML document of the form.  You'll have to use XPath to locate the particular firstname field inside of the document.  There are several code examples in the forums of how to access XML field values.


Another thought.  Although you can write the code you are describing in the destination rule, you might want to write it server event.  Right-click, properties, view code, event item.


Brilliant, thanks! I searched for XPath and found the following thread which helped me resolve the problem:


http://k2underground.com/forums/thread/20938.aspx


Reply