Accessing datafields from a workflow

Last post 03-03-2008, 10:47 AM by PiratesOfThe[blackpearl]. 3 replies.
Sort Posts: Previous Next
  •  03-03-2008, 9:12 AM 22250

    Accessing datafields from a workflow

    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. 

     

  •  03-03-2008, 9:25 AM 22252 in reply to 22250

    Re: Accessing datafields from a workflow

    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

  •  03-03-2008, 9:41 AM 22253 in reply to 22250

    Re: Accessing datafields from a workflow

    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.


    The statements and opinions made in my postings are my own, and do not reflect the opinions of SourceCode Technology Holdings, Inc. or its subsidiaries. All information is provided as is with no warranties, express or implied, and grants no rights or licenses.
    Filed under: ,
  •  03-03-2008, 10:47 AM 22256 in reply to 22253

    Re: Accessing datafields from a workflow

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

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

View as RSS news feed in XML