Making a submit button for K2 in Vis Studio 2005


Badge +3

I have a webpage and want the submit button of that page to take me to the next step in my K2 Flow. So I wrote some code in Visual Studio 2005 and added a reference to K2ROM. However, K2ROM.Connection and K2ROM.WorklistItem won't compile because it says they are not defined. But I did the imports so I'm not sure what is wrong.


I am also not sure how to call OpenWorklistItem() 


 Thanks.


Imports SourceCode.K2ROM
Imports SourceCode.K2ROM.Connection
Imports SourceCode.K2ROM.Worklist
Imports SourceCode.K2ROM.ServerItem
Imports SourceCode.K2ROM.ProcessInstance
Imports SourceCode.K2ROM.WorklistItem



Partial Class _Default


    Inherits System.Web.UI.Page



    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        sender.OpenWorklistItem("k2megasrv", "K2SRV")
    End Sub



    Private Sub OpenWorklistItem(ByVal strK2Server As String, ByVal strSerialNumber As String)


        Dim oK2Connection As K2ROM.Connection
        Dim oWorklistItem As K2ROM.WorklistItem


        Try
            'Open Connection
            oK2Connection.Open(strK2Server)
            'Get the worklistItem based on the SerialNumber
            oWorklistItem = oK2Connection.OpenWorklistItem(strSerialNumber, "ASP", True, False)


            'Update Process Data or XML Field
            oWorklistItem.ProcessInstance.DataFields("Result").Value = "Complete"
            oWorklistItem.ProcessInstance.XmlFields("Date").Value = Date.Today
            oWorklistItem.ProcessInstance.XmlFields("Time").Value = TimeOfDay.Hour & ":" & TimeOfDay.Minute


            'Update Activity Data or XML Field
            oWorklistItem.ActivityInstanceDestination.DataFields("Result").Value = "Complete"
            oWorklistItem.ActivityInstanceDestination.XmlFields("Date").Value = Date.Today
            oWorklistItem.ActivityInstanceDestination.XmlFields("Time").Value = TimeOfDay.Hour & ":" & TimeOfDay.Minute


            oWorklistItem.Update()
            'OR
            oWorklistItem.Finish()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub



End Class


13 replies

Badge +5

Hi mbotella,


You've defined variables as a Connection and WorklistItem object buy you forgot to instantiate a new instance of them.


Dim oK2Connection As K2ROM.Connection = New K2ROM.Connection (or simpler) Dim oK2Connection as New K2ROM.Connection.  Same is true for the WorklistItem object.


If you look under the "References" section of the K2.net Help file you'll find examples on how to call the OpenWorklistItem() method.


Also, in your Button1.Click event handler you have sender.OpenWorklistItem().  That's also probably not compiling as sender is the button and OpenWorklistItem is not a valid method.


-mike

Badge +3

Thanks for the reply. I am having a bit of server communication issues at my oK2.Connection.OpenWorklistItem("k2megarsv, ProcessInstanceID, EventInstanceID", "k2megasrv") call. I am not exactly sure which params to put in.


 Partial Class _Default


    Inherits System.Web.UI.Page



    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oK2Connection As New SourceCode.K2ROM.Connection
        Dim oWorklistItem As SourceCode.K2ROM.WorklistItem
        oK2Connection.OpenWorklistItem("k2megarsv, ProcessInstanceID, EventInstanceID", "k2megasrv")


 


    End Sub



    Private Sub OpenWorklistItem(ByVal strSerialNumber As String, ByVal strK2Server As String)


        Dim oK2Connection As SourceCode.K2ROM.Connection
        Dim oWorklistItem As SourceCode.K2ROM.WorklistItem



        Try
            'Open Connection
            oK2Connection.Open(strK2Server)
            'Get the worklistItem based on the SerialNumber
            oWorklistItem = oK2Connection.OpenWorklistItem(strSerialNumber, "ASP", True, False)


            'Update Process Data or XML Field


....

Badge +3
And I just realized I don't need this  Dim oWorklistItem As SourceCode.K2ROM.WorklistItem in the Button function
Badge +5

Between the two methods above you've got everything you need.  You just need to combine the good stuff 🙂

Dim cnn as New Connection
Dim wli as WorklistItem


cnn.Open(strK2Server)
wli = cnn.OpenWorklistItem(strSerialNumber, "ASP")

'Update the worklistitem and finish it.
wli.ProcessInstance.DataFields("MyFields").Value = "Some Text"
wli.Update()
'or
wli.Finish()

Badge +3

That makes sense but don't I need to still call the function? It doesn't like the call inside the Submit Button function because it doesn't recognize the server.


 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oK2Connection As New SourceCode.K2ROM.Connection


        oK2Connection.OpenWorklistItem("k2megasrv, ProcessInstanceID, EventInstanceID", "k2megasrv")


    End Sub



    Private Sub OpenWorklistItem(ByVal strSerialNumber As String, ByVal strK2Server As String)


        Dim oK2Connection As New SourceCode.K2ROM.Connection
        Dim oWorklistItem As SourceCode.K2ROM.WorklistItem


        Try
            'Open Connection
            oK2Connection.Open(strK2Server)
            'Get the worklistItem based on the SerialNumber
            'oWorklistItem = oK2Connection.OpenWorklistItem(strSerialNumber, "ASP", True, False)
            oWorklistItem = oK2Connection.OpenWorklistItem(strSerialNumber, "ASP")
            'Update Process Data or XML Field
            oWorklistItem.ProcessInstance.DataFields("Result").Value = "Complete"
            oWorklistItem.ProcessInstance.XmlFields("Date").Value = Date.Today
            oWorklistItem.ProcessInstance.XmlFields("Time").Value = TimeOfDay.Hour & ":" & TimeOfDay.Minute


            'Update Activity Data or XML Field
            oWorklistItem.ActivityInstanceDestination.DataFields("Result").Value = "Complete"
            oWorklistItem.ActivityInstanceDestination.XmlFields("Date").Value = Date.Today
            oWorklistItem.ActivityInstanceDestination.XmlFields("Time").Value = TimeOfDay.Hour & ":" & TimeOfDay.Minute


            oWorklistItem.Update()
            'OR
            oWorklistItem.Finish()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub

Badge +5

I think there's something confusing you here.  First to clear things up change your private sub's name from OpenWorklistItem to OpenTaskItem.  In your button's click event handle all you need to have in there is a call to you now OpenTaskItem method.


Now, even though your going to change the code in the button event handler method I want to point something out.  Closely look at how your calling oK2Connection.OpenWorklistItem("k2megasrv, ProcessInstanceID, EventInstanceID", "k2megasrv"). A correct serial number looks like this "k2megasrv,104,21".  You've got the actual word ProcessInstanceID and EventInstanceID.


So, before you call your newly renamed method (OpenTaskItem) from you buttons click event handle you need to get the actual serial number.  This is normally part of the query string so what you can do is Request.QueryString("sn")


Your button click event method now looks like this:
Dim sn as string = Request.QueryString("sn")
OpenTaskItem(sn, "k2megasrv")


Finally, i see you want to update some xml fields. Even though you may have copied that directly from the help file it is incorrect.  The datafields are correct so just comment out the xml fields.  When you get this solution up and working I think it's worth while creating a new post regarding the data fields.


Oh, and 1 more thing.  In your try-catch, put a finally section in there and call oK2Connection.Close(). 

Badge +3

Thanks a lot for the help!


When I try to debug the submit button won't work because I have an invalid serial number. When I try to open the page from the worklist it says i am not authorized to view the page. But I thought I had all the users permissions. I am publishing to this web site: http://localhost/WindowsApp and using a default client event to publish my site. do you think that's not a good site to use?

Badge +5

make sure the indentity tag is in your web.config file.

<system.web>
       <identity impersonate="true" />
<system.web/>


Also check that the IIS site that you are publishing to is using integrated authentication and not anonymous. And please feel free to contact your local K2 Support team as they will most likely do a live meeting with you and have you up and running in no time.

Let me know if you need any more assistance.


-mike

Badge +3

Do you know how I could get a hold of my local K2 Support team?


 I can't figure out why I am getting an invalid serial number  when I try to debug my site/the user cannot open the site from their workspace because they are not authorized to.


 Thanks.

Badge +5
What continent do you reside in?
Badge +3
i'm in north america
Badge +5
1-877-8CALLK2
Badge +1

Oh....Looks good, but my question is when user requested and created one new process, how can I know or find which Process SerialNumber is newly created? If we do not have this key ,we can not do any thing to the worklist item.,


Thanks

Reply