Skip to main content
I am trying to update just the process instance data for a given worklist item. There is some .Net 2.0 code that looks for incoming e-mails, processes them, and adds to the journal of the worklist item, but it does this all to a database and not to K2. So, since there aren't any calls to K2, I was curious how to update it without advancing K2 to another Activity? Here is the code that I'm trying to use, but it currently doesn't work, it fails at process.CurrentWorklistItem.ProcessInstance.DataFields....

//***********************************
string _k2ServerName = "MTRAN-SHARE02";
string _k2ProcessName = "MTSSupportTicket";
WorklistItem _k2WorklistItem;
Connection _k2Connection = new Connection();
_k2Connection.Open(_k2ServerName);
ProcessInstance _k2ProcessInstance = _k2Connection.CreateProcessInstance(_k2ProcessName);
ProcessDataFields _processDataFields = new ProcessDataFields();

try
{
WorklistCriteria worklistCriteria = new WorklistCriteria();
worklistCriteria.AddFilterField(WCField.ProcessID, WCCompare.Equal, supportTicket.K2ProcessId);
Worklist worklist = _k2Connection.OpenWorklist(worklistCriteria);
if (worklist.Count == 1)
{
// we should have just one task
_k2WorklistItem = worklist[0];
_k2ProcessInstance = _k2WorklistItem.ProcessInstance;
}
}
catch
{
}

_processDataFields.Clear();
foreach (DataField df in _k2ProcessInstance.DataFields)
{
try
{
_processDataFields.Add((SupportTicketData)Enum.Parse(typeof(SupportTicketData), df.Name, true), df.Value);
}
catch (Exception) { }
}

SupportTicketProcess process = new SupportTicketProcess(_k2ServerName, _k2ProcessName);
process.OpenNextWorklistItem(supportTicket.K2ProcessId);
supportTicket.StatusDescription = "User Feedback Received";
process.CurrentWorklistItem.ProcessInstance.DataFields[SupportTicketData.StatusDescription] = supportTicket.StatusDescription.ToString();
supportTicket.StatusDescription.ToString();
process.CurrentWorklistItem.Update();


//***********************************/
Hi Doug.

Try adding a ".Value" on the Process Data Field line to the following line:

 = supportTicket.StatusDescription.ToString(); 


So it reads like:

.Value = supportTicket.StatusDescription.ToString(); 

Well, I tried that and it said that there were invalid arguments on that line. So, I tried something different and did this to simplify it all and see where the issue was:

 = supportTicket.StatusDescription;
_k2ProcessInstance.Update();


Now, I'm getting an invalid arguments on the similar line, second from the last, and it says that it can't convert from a SupportTicketData type to a string.
You should add the ".Value" to that line also ("_k2ProcessInstance.DataFields[SupportTicketData.StatusDescription].Value").

Any time you want to set the value of a data field you need to reference the Value property of the datafield object, not the datafield object itself. "_k2ProcessInstance.DataFields[SupportTicketData.StatusDescription]" is a data field object.
I actually did try that, it just happened that the one I pasted in didn't have it. When I do that it comes back saying that "_k2ProcessInstance.DataFields[SupportTicketData.StatusDescription]" has some invalid arguments and that it can't convert the SupportTicketData to a string. Does any of this change when you are using Visual Studio instead of the K2 studio or with C# ?
Are you receiving this error at compile time or execution/run time?

Are you positive that the data type of SupportTicketData.StatusDescription is a string?

K2ROM code such as this is usually executed from within an external application (that had been developed in VS.NET). There are syntactical differences between C# and VB.NET, but that is not unique to K2ROM but all .NET code.
I am receiving the error at compile time, and yes, I double and triple checked that it was a string.
If you're willing to post your code here, I'll review it. Perhaps I'm misunderstanding the issue and seeing the entire code would quickly identify it.
Hi,

Just to test try replacing SupportTicketData.StatusDescription with the actual name of a data field in your process. As per your code it looks like your data field is called: User Feedback Received, if this is the case, change your code like this:
.Value

Changes to:
.Value 


If this updates the value then the problem lies with the SupportTicketData.StatusDescription call.

Hope this helps!

JohanL

Reply