Worklist item not found


Badge +2
When viewing worklist items outside of the workspace, say on a website using SmartForms, is there a way to catch for this error "Worklist item not found" to show a user friendly error stating that this item has already completed or is expired?

6 replies

Badge +7
You may use standard ASP.NET error handling methods in K2.net SmartForms.

There are 2 methods of handling Page level errors:
Method 1: Page redirection
Unforeseen errors can be trapped with the ErrorPage property of the Page object. This allows definition of a redirection URL in case of unhandled exceptions. To enable such error trapping, set the customErrors attribute of your web.config file, as follows: <customErrors mode="On" />

Insert/Edit this line into your ASP.NET page's HTML source:

<%@ Page ErrorPage="http://<server>/GenericError.htm" %>


Method 2: Using the Page objects error event to capture exceptions
The Page object has an error event that is fired when an unhandled exception occurs in the page.

The following sample code below allows you to handle a ASP.NET Page level error.
Sub Page_Error(sender as Object, e as EventArgs)

dim PageException as string = Server.GetLastError().ToString()
dim strBuild as new System.Text.StringBuilder
strBuild.Append("Exception!")
strBuild.Append(PageException)

Response.Write(strBuild.ToString())
Context.ClearError()

End Sub

The above suggestions are standard ASP.NET error handling methods. You should be able to find more information on these methods easily.
Badge +3
Hi,

I read with interest SamuelKoh's suggested methods to catch the 'Worklist item not found' error. I tried both methods, but neither of them worked probably because K2 code-behind actually handles the error and issues a Response.Write? Is there a way to handle the error more gracefully?

Thanks
Badge +11
What I usually do, is to create a separate aspx page with a couple of lables on it - call it 'CheckWLI.aspx'. In this page, I first check to see that the Worklist item can be found, is not allocated to a different user and the Serial number is correct - as in code below. When all tests succeed, I would redirect to the actual Client page.

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

Dim SN As String
SN = Request.QueryString("SN")

checkForWLI(SN)

End Sub

Private Sub checkForWLI(ByVal SN As String)
Dim conn As New SourceCode.K2ROM.Connection
Dim K2Server As String = System.Configuration.ConfigurationSettings.AppSettings("PlanServer")

Try
conn.Open(K2Server)
Dim WLI As SourceCode.K2ROM.WorklistItem

WLI = conn.OpenWorklistItem(SN, "ASP")
Response.Redirect("CallLog.aspx?SN=" + SN)

Catch ex As Exception
If (ex.ToString().ToLower().IndexOf("worklist item not found") > -1) Then
' worklist item has either been processed or is in an error state.
lblHeader.ForeColor = System.Drawing.Color.Blue
lblHeader.Text = "Worklist Item not Found!"
lblMsg.ForeColor = System.Drawing.Color.Blue
lblMsg.Text = "Worklist item has either been processed or is in an error state."
ElseIf (ex.ToString().ToLower().IndexOf("allocated") > -1) Then
' worklist item is already allocated to a different user.
lblHeader.ForeColor = System.Drawing.Color.Blue
lblHeader.Text = "Worklist Item Already Allocated!"
lblMsg.ForeColor = System.Drawing.Color.Blue
lblMsg.Text = "Worklist item is already allocated to a different user."
ElseIf (ex.ToString().ToLower().IndexOf("invalid serialnumber") > -1) Then
' Invalid Serial Number
lblHeader.ForeColor = System.Drawing.Color.Red
lblHeader.Text = "ERROR!"
lblMsg.ForeColor = System.Drawing.Color.Red
lblMsg.Text = "Invalid Serial Number"
Else
' an unknown error has occurred.
lblHeader.ForeColor = System.Drawing.Color.Red
lblHeader.Text = "ERROR!"
lblMsg.ForeColor = System.Drawing.Color.Red
lblMsg.Text = ex.Message
End If
Finally
conn.Close()
End Try

End Sub


Hope this helps,
Ockert
Badge +3
Thanks Ockert! I will give this a try.
Badge +3
I'm also using similar code that Samualkoh suggested (the second suggestion) to catch certain errors and return a "user friendly" message. Overall, this method has worked fine. The problem that I am now encountering is where the user is presented with the first screen to initiate the process but does not submit the page until after IIS times out (about 20 minutes). After 20 minutes, the user clicks on the submit button (a K2 submit button) and receives an "Object not found" error.

What I have noticed is that, the Page_Error routine is involked after the click processing for the submit button has been completed. On the initial pass, the error message "Connection to the K2.net server wrkflowdev1-cpf is invalid." is returned from the server.getlasterror which is correct. However when stepping through the code in debug mode, I notice that the Page_Error routine in involked again (after exiting when processing of the initial error message complete). This time, an Object not found error message is displayed when trying to do the server.getlasterror.

The Page_Error routine has a clearerror method that is executed as shown in the samples.

Does anyone have any suggestions as to what could be causing this problem?

Thank you in advance for your help.
Badge +11
I think the problem lies in the fact that the Page_Error event is called once for the SmartForm (inherited object) and once for the Page (Base object). On the second pass, the objects contained within the SmartForm scope probably does not exist any more. Maybe you can set a flag during the first pass which will stop any code from executing on the second pass.

Not sure if this would work... Just a suggestion.

Regards,
Ockert

Reply