Code for ServerEvent - K2.ProcessInstance has no ID / DataFields / etc

  • 1 September 2016
  • 4 replies
  • 0 views

Badge +1

Hi - I'm new to writing code for K2.

 

I have added code to my ServerEvent in my workflow. I was wanting to get a value from the K2.ProcessInstance.DataFields, but get an error that the DataFields don't exist in my current context. I then tried just taking a look at the K2.ProcessInstance, running my workflow in debug & attaching to the K2 host process, but I only seem to have non-public members. I'm assuming I am doing something ridiculous. Any idea what?

11637iA49B8C0649FA5A79.png


4 replies

Userlevel 1
Badge +8

Hi Hilary

 

You can use the following as an example of how to get the value of a data field:

 

 string datafieldvalue = K2.ProcessInstance.DataFields["MyDataField"].Value.ToString();

Badge +1

Thanks! But even somthing like this, where I use 0 for an index to remove any chance of error for datafield name, I get an error that indicates there are no datafields:16327iB0562B72CBDC16AD.png

 

Userlevel 1
Badge +8

Hilary

 

Can you send a screen shot of your workflow data fields?

Badge +1

I knew I was doing something silly. I needed to add & set the data fields, then they were available in code. Thanks for pointing me in the right direction!

Reply