Skip to main content
I want to submit the InfoPath form on clicking any custom button to K2.NET. I dont want to use the K2.Net taskpane. Can someone help me how to submit the form to K2.Net using custom c# code ?

Thanks,
Try to look at the scripting code behind the page (Tools/Script/MS Script Editor) - perhaps you can copy the relevant script from there into a button's click event on the form.

I haven't tried this before so I'm not sure if it will work but perhaps worth a try.
Hi.
You need to K2-enable your InfoPath document. In other words, run through the InfoPath process wizard in K2.net Studio and point it to your InfoPath doc. This will create a "Main Submit" data connection to your K2 InfoPath web service. (Obviously you don't want the task pane, so leave this checkbox unchecked in the wizard).

Then, in InfoPath add your custom button and go to "Button Properties" and click on "Edit Form Code ...". Microsoft Script Editor will open or the C# editor and you will be inside the click event of the button. Add the following.
In script editor:
XDocument.Submit();
In C#:
thisXDocument.Submit();

This should take care of it.

By the way, you can do it the other way around and it should work as well. I.e. create the button with the submit code first and then run it through the K2 InfoPath process wizard.
Does K2.net override an OnSubmitRequest() event handler?

I'd like to do as suggested in this thread, but I'd also like to use OnSubmitRequest() to ensure the form is error free before submission.

Thanks,
David.
It is safe to say that the IP Process wizard will not override any code in the OnSubmitRequest() method.
I'm not so sure... when I run the InfoPath wizard on my form the OnSubmitRequest() event handler is no longer run.

Prior to running the wizard it doesn't matter if I set my button to a 'Submit' action or to 'Rules and Custom Code' and call thisXDocument.Submit() within the button's event handler - either way OnSubmitRequest() is called.

After running the wizard, there doesn't appear to be any way in which I can get OnSubmitRequest() to be called. If I set my button to the 'Submit' action it calls the K2.net web service and the form is submitted without calling OnSubmitRequest(). If I set my button to 'Rules and Custom Code' then the event handler for the button is called, the form is submitted but again OnSubmitRequest() is never reached.

Any suggestions?
With a little more digging, it would appear that OnSubmitRequest isn't called when I used any web service to submit the form.

Hopefully I've solved the issue by explicitly calling a validation function before the Submit() operation takes place.
To follow up on this issue, I'd explicitly disabled the Submit button on the File Menu by unchecking the option within the Submitting Forms dialog.

However when I update the document from within K2 Studio, the submit button is introduced on both the taskbar and the file menu. Clicking on this button bypasses any custom validation I've written because OnSubmitRequest() isn't called (see above messages) and therefore it is possible for a user to submit invalid forms.

Can I please receive some advice on how to either:
a) get rid of the Submit options on the taskbar and file menu, or
b) ensure that OnSubmitRequest or another event handler is called when the user submits the form using the task bar or file menu option.

Thanks,
David.
I have a solution of sorts...

Once I've published the InfoPath form to SharePoint then updated the document using K2 Studio, I then save the form locally and open it in design mode, uncheck the 'Enable the Submit menu item on the File menu' option and finally re-publish the form to the original location.

Can anyone from K2 please let me know if there is a way to prevent K2 from re-introducing the Submit option (and thus save me from re-publishing)?
In the Infopath process wizard - step 4 of 7, there's a check box selection - "Display Taskpane with Submit button". Have you checked this option?

Regards,
Ockert
No, I'm not using the K2 Task Pane.

Instead I have a button which is used to submit the form, the code behind the button submits the form with a call to thisXDocument.Submit().
When K2.net Studio updates the InfoPath doc, it assumes that when you do not want the K2.net task pane that you will need a Submit button on the menu bar. There is no way for K2.net Studio to know that you have your own Submit button on the form and that you do not need the Submit button on the menu item. So, to cater for users that do not have their own Submit button and do not want to go and write script to add one or turn on the Menu item, it always displays the button when there is no task pane.

Unfortunately you will have to disable the Submit button each time you executed the wizard.
Thanks for the explanation.

Re-publishing the form isn't too onerous and hopefully this thread will be of use to others in the same situation.
It certainly was. Thank you.

Reply