Save Serial Number to SQL

  • 15 November 2012
  • 3 replies
  • 15 views

Badge +2

I have created an extremely simple workflow.  I want to start it from outside k2 using the  CreateProcessInstance function.  Then I will action the workflow steps from outside K2 as well.  The problem I'm having is I don't know the serial number when the process instance gets created.


I created a smartobject that can update a table and put in the serial number into a field.  I also created a data field to store the primary key of the record in the table to set the serial number for.  I assign the primary key to the process instance before starting it (pi.DataFields[1].Value = <ID here>;). the first step in the workflow I tried a smartobject event to use my update smart object.  I set the ID = the variable, and the serial number = ProcessId_ActivityInstanceDestId.


Every time I try to run the process I get an error message about "Nullable object must have a value".  Any ideas on this?


3 replies

Badge +8

I think you are going about this in the wrong way.  To access a worklist item, you need to use the Connection.OpenWorklistItem() method from the API.  This method accepts a single parameter: the serial number of the worklist item you are opening..  The returned WorklistItem object will contain a SerialNumber property.


However, you won't be able to get to the serial number until K2 generates it for the activity.  Typically users are informed of this by embedding the serial number in a URL, for example.  Serial numbers are only valid for the specific activity instance for which they were created.  In other words, if your process loops back to the same activity, it won't have the same serial number the second time it goes to the same activity.  So I don't think storing serial numbers in SQL will do what you think it will.


But for what it's worth, the serial number is always <Process Instance ID>_<Activity Instance Destination ID>.

Badge +2

Can you suggest an alternative way of accessing the process if serial number won't work?  The client wants a k2 workflow that I will access from code to move to the next step.  it's really only there to provide escalations if the process hasn't moved in x number of days.  So the workflow never interacts with anything else.  It just gets accessed from an external website via a webservice.

Badge +1

Have you thought about using the WCF?  You could do something like the following




WorklistNavigationServiceClient



 



 



worklistNavigationServiceClient = new WorklistNavigationServiceClient();


 



Criteria



 



 



criteria = new Criteria();

 



 



List<CriteriaFilter> criteriaFilter = new List<CriteriaFilter>

{



 



 



new CriteriaFilter



{



Field =



 



CriteriaField.ProcessID,

Comparison =



 



CriteriaComparison.Equal,

Value = processId.ToString(),



ValueType =



 



ValueType.Integer

}


};


criteria.Filter = criteriaFilter.ToArray();



 



 



WorklistItem worklistItems = worklistNavigationServiceClient.OpenWorklistFiltered(criteria, false, false, false, false);



 



 



return worklistItem;

}


You can the get back a serialnumber and any other information you may need for the worklist item.




 


Reply