Skip to main content

Hello,


I'm writing some code in a K2 custom server event through K2 for Visual Studio. In the code below, I've found that I can easily write to K2.ProcessInstance.DataFields, but that I can't seem to read from the DataFields.


//Set date submitted
K2.ProcessInstance.DataFields["Date Submitted"].Value = DateTime.Now.ToShortDateString();


//Get Document Attributes
LogMessageToFile("Doc ID from DataFields = " + K2.ProcessInstance.DataFields["Doc ID"].Value.ToString());


The Date Submitted is correctly set and I can read from it later through the K2 interface. The message logged to my text log file shows a blank in the place of the Doc ID value. I know the Doc ID has a value b/c I also am writing the Doc ID to a column at another step and can see the correct value in the column on my SharePoint site.


 Has anyone else seen this behavior, or am I missing a step?


Thanks,


Kim

There should be no problem reading DataFields.  Has the "Doc ID" field been set before this step? 


Yes, the Doc ID has been set as noted above:


" I know the Doc ID has a value b/c I also am writing the Doc ID to a column at another step and can see the correct value in the column on my SharePoint site."


This might look like a long way to do the same thing but I've seen this sometimes help (not neccessarily with K2 DataFields but in general)


string DocID = K2.ProcessInstance.DataFields["Doc ID"].Value.ToString();
LogMessageToFile("Doc ID from DataFields = " + DocID);


Does that make any difference?


Alternatively, could you attach to the server process with (remote) debugging and step through the code to check what's happening with the data fields?


 


There should be no problem readin data fields, i am able to set/get that in my code


if

(item.ProcessInstance.DataFieldss"whatever"].Value.ToString() == "yes").


do have a look in code and make sure that your are setting it , also if you could post all code.


If problem is solved , do post a solution so that all of us can see the solution.


 


Cheers!


 


Looks like GLouw's solution worked.


Thanks!


Reply