HI,
Try to take a log for the execution of the code. That's what I do normally to bedug the coed at run time.
Â
1. Copy and paste the following method in code behind
2. Create two .txt file For tracing the output
3. Use the LogFile in your code as follows:
4. Check the logfile for the status of the checkpoint.
Â
Also, check for the K2Server connection string. take a log for this too.
Â
K2Server.Open(_serverName, connectionString.ToString());
Worklist wl = default(Worklist);
WorklistCriteria wc = new WorklistCriteria();
wc.AddFilterField(WCField.SerialNumber, WCCompare.Equal, serialNumber);
wl = K2Server.OpenWorklist(wc);
Â
LogFile("CheckPoint-1 wl.count value: " + wl.count + Environment.NewLine);
if (wl.Count > 0)
{
LogFile("CheckPoint-2Â inside count greater than 0." + Environment.NewLine);
WorklistItem wItem = default(WorklistItem);
wItem = wl 0];
var allocatedUser = wItem.AllocatedUser;
wi = K2Server.OpenWorklistItem(serialNumber, "ASP");
LogFile("CheckPoint-3." + Environment.NewLine);
}
else
{
LogFile("CheckPoint-4Â return value assigned failed" + Environment.NewLine);
returnValue = "failed";
}
LogFile("CheckPoint-5Â wi value: " + wi+Environment.NewLine);
Â
if ( (wi != null) & (actionValue.Trim() == "Y"))
{
   LogFile("CheckPoint-6 " + wi+Environment.NewLine);
 wi.ActionsÂ"Successful"].Execute();
}
Â
Â
Here is the code:
Â
private static void LogFile(string sMsg)
{
string sLogFile = "C:WorkflowLogK2Log.txt";
string sLogBackup = "C:WorkflowLogK2LogBak.txt";
FileInfo fi = new FileInfo(sLogFile);
try
{
if (File.Exists(sLogFile) && (fi.Length >= 100000))
{
File.Delete(sLogBackup);
File.Copy(sLogFile, sLogBackup);
File.Delete(sLogFile);
}
File.AppendAllText(sLogFile, sMsg);
}
catch (Exception exc)
{
string sErr = exc.Message + exc.StackTrace;
}
}
}
Â
Thank you for providing this code however these exceptions do not occur in lower environments but only in PRODUCTION or LIVE environment.
So couldn’t find where these exceptions are occurring.
Â
Â
I have one query please find below code:
Â
WorklistItem wItem = default(WorklistItem);
wItem = wl 0];
var allocatedUser = wItem.AllocatedUser;
wi = K2Server.OpenWorklistItem(serialNumber, "ASP");
if ( (wi != null) & (actionValue.Trim() == "Y"))
{
 wi.Actions<"Successful"].Execute();
}
Â
Can wi.Actions be null ? Can this be the cause of these exceptions?
Â
Request you to please provide any information regarding this.
Â