Skip to main content
After usng WorklistCriteria and retrieving a list of workitems, I can not find the property value for ProcID. It has ProcInstI.ID and this Workitem.ID -- which is not the ProcID.

ProcID is needed to pass to xmlData.aspx to display XML form data.

The workaround for this would be to store the ProcID in a hidden Process Data field.

How would you get the ProcID from within the process to the process data field?


I don't see it exposed within a ServerEventContext object.  Perhaps I'm misunderstanding.


oK2Manager.GetProcessInstancesAll

oProcessInstance.ProcID

I ended up just putting the latest ID in a StringTable value for now. 


I've run into this type of problem several times in the past.  It can be frustrating when the K2 object model doesn't provide all the relevant fields for a given entity even though you know they exist but are just not exposed.  Unfortunately, we haven't found a nice and clean way of going about this.

The route we chose to take was to create a web service that runs against the k2 database to get the data we need.  I'm not advocating this approach, but sometimes it's the only way to get the data you need.  If anyone takes this route, you'll have to test it with every new release from K2.

 
For example, you'd think that you should be able to get the finish activity name for a given line or line ID, but you can't.  If you attempt to get the finish activity name from the line rule instance, the finish activity is null.  Obviously the finish activity probably hasn't run yet if I'm in the line rule, but I just want to get the finish activity name.  It's clearly there in the database, but the API wont give it to you.  Therefore I wrote a function...

 

 public string GetFinishActivityName(string lineName, int processInstanceId)
        {
            string sql = @"
                select aStart.Name as 'StartName' , aFinish.Name as 'FinishName', l.*
                from _line l inner join
                 _procInst pInst on pInst.ProcID = l.ProcID inner join
                  _act aStart on l.StartId = aStart.ID inner join
                    _act aFinish on l.FinishId = aFinish.ID
                where l.name = @lineName
                and pInst.ID = @procInstId
                ";

            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings "K2LogConnectionString"]);
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlParameter paramLineName = cmd.Parameters.Add("@lineName", SqlDbType.VarChar);
            SqlParameter paramProcInstId = cmd.Parameters.Add("@procInstId", SqlDbType.Int);
            
            paramProcInstId.Value = processInstanceId;
            paramLineName.Value = lineName;

 

                cmd.Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                reader.Read();

                string finishActivity = reader.GetString(reader.GetOrdinal("FinishName"));
                if (readeroreader.GetOrdinal("FinishName")] == DBNull.Value || finishActivity == null)
                {
                    throw new Exception(string.Format("Couldn't not get a finish activity name value for line name: {0} and process                     instance id {1}",
                        lineName, processInstanceId));
                }
                return finishActivity;

}

 


Reply