Error when submitting a new SharePoint Calendar Item

F

Fernando

Hi there,

Firstly I would like to thank S.Y.M Wong A Ton for all her help! I hope she
reads this post... :)

I followed the steps at
http://enterprise-solutions.swits.n...m-sharepoint-calendar-infopath&c=infopath2007

The end result is successful. The items are added to the specified Calendar.
However, I receive an error message when clicking the submit button: Infopath
cannot submit the form. The OnSubmitRequest event handler returned a value
indicating that the submit failed. This occures if I use C# or VB.

I am not a coder in any way. I can understand code once I see it but I know
nothing about creating it.

In saying that I would also like to close the form once it has been
submitted. I can do this using rules but as you know you can't use rules when
using the "Edit Code" submit option.

Your assistance would be greatly appreciated.
 
S

S.Y.M. Wong-A-Ton

F

Fernando

Hi there. Thank you for your reply!

I don't know... but this is the code I have.

--------------------------------------
using Microsoft.Office.InfoPath;
using System;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using mshtml;

namespace Leave_Form_Part3_1._
{
public partial class FormCode
{
// Member variables are not supported in browser-enabled forms.
// Instead, write and read these values from the FormState
// dictionary using code such as the following:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }

// NOTE: The following procedure is required by Microsoft Office
InfoPath.
// It can be modified using Microsoft Office InfoPath.
public void InternalStartup()
{
EventManager.FormEvents.Submit += new
SubmitEventHandler(FormEvents_Submit);
}

public void FormEvents_Submit(object sender, SubmitEventArgs e)
{
XPathNavigator root = MainDataSource.CreateNavigator();

// Retrieve the values for the calendar item
string title = root.SelectSingleNode("my:myFields/my:title",
NamespaceManager).Value;
string location = root.SelectSingleNode("my:myFields/my:location",
NamespaceManager).Value;
string startDate =
root.SelectSingleNode("my:myFields/my:startDate",
NamespaceManager).Value;
string startTime =
root.SelectSingleNode("my:myFields/my:startTime",
NamespaceManager).Value;
string endDate = root.SelectSingleNode("my:myFields/my:endDate",
NamespaceManager).Value;
string endTime = root.SelectSingleNode("my:myFields/my:endTime",
NamespaceManager).Value;
string allDayEvent =
root.SelectSingleNode("my:myFields/my:allDayEvent",
NamespaceManager).Value;

XPathNavigator batch = DataSources["EventCAML"].CreateNavigator();

// Set the title
batch.SelectSingleNode("/Batch/Method/Field[@Name='Title']",
NamespaceManager).SetValue(title);

// Set the location
batch.SelectSingleNode("/Batch/Method/Field[@Name='Location']",
NamespaceManager).SetValue(location);

// Set the start date
batch.SelectSingleNode("/Batch/Method/Field[@Name='EventDate']",
NamespaceManager).SetValue(startDate);

// Set the end date
batch.SelectSingleNode("/Batch/Method/Field[@Name='EndDate']",
NamespaceManager).SetValue(endDate);

// Set the all day event

batch.SelectSingleNode("/Batch/Method/Field[@Name='fAllDayEvent']",
NamespaceManager).SetValue(allDayEvent);

// Submit the item details to the web service to update the
calendar
DataConnections["Web Service Submit"].Execute();

}
}
}
 
S

S.Y.M. Wong-A-Ton

You need to put a try-catch block around the code and if no errors occurred,
set

e.CancelableArgs.Cancel = false;

to indicate that the submit operation was successful. See
http://msdn2.microsoft.com/en-us/li...th.submiteventargs.cancelableargs(VS.80).aspx
---
S.Y.M. Wong-A-Ton


Fernando said:
Hi there. Thank you for your reply!

I don't know... but this is the code I have.

--------------------------------------
using Microsoft.Office.InfoPath;
using System;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using mshtml;

namespace Leave_Form_Part3_1._
{
public partial class FormCode
{
// Member variables are not supported in browser-enabled forms.
// Instead, write and read these values from the FormState
// dictionary using code such as the following:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }

// NOTE: The following procedure is required by Microsoft Office
InfoPath.
// It can be modified using Microsoft Office InfoPath.
public void InternalStartup()
{
EventManager.FormEvents.Submit += new
SubmitEventHandler(FormEvents_Submit);
}

public void FormEvents_Submit(object sender, SubmitEventArgs e)
{
XPathNavigator root = MainDataSource.CreateNavigator();

// Retrieve the values for the calendar item
string title = root.SelectSingleNode("my:myFields/my:title",
NamespaceManager).Value;
string location = root.SelectSingleNode("my:myFields/my:location",
NamespaceManager).Value;
string startDate =
root.SelectSingleNode("my:myFields/my:startDate",
NamespaceManager).Value;
string startTime =
root.SelectSingleNode("my:myFields/my:startTime",
NamespaceManager).Value;
string endDate = root.SelectSingleNode("my:myFields/my:endDate",
NamespaceManager).Value;
string endTime = root.SelectSingleNode("my:myFields/my:endTime",
NamespaceManager).Value;
string allDayEvent =
root.SelectSingleNode("my:myFields/my:allDayEvent",
NamespaceManager).Value;

XPathNavigator batch = DataSources["EventCAML"].CreateNavigator();

// Set the title
batch.SelectSingleNode("/Batch/Method/Field[@Name='Title']",
NamespaceManager).SetValue(title);

// Set the location
batch.SelectSingleNode("/Batch/Method/Field[@Name='Location']",
NamespaceManager).SetValue(location);

// Set the start date
batch.SelectSingleNode("/Batch/Method/Field[@Name='EventDate']",
NamespaceManager).SetValue(startDate);

// Set the end date
batch.SelectSingleNode("/Batch/Method/Field[@Name='EndDate']",
NamespaceManager).SetValue(endDate);

// Set the all day event

batch.SelectSingleNode("/Batch/Method/Field[@Name='fAllDayEvent']",
NamespaceManager).SetValue(allDayEvent);

// Submit the item details to the web service to update the
calendar
DataConnections["Web Service Submit"].Execute();

}
}
}
------------------------------------

I hope this helps. Thank you again for your time.

S.Y.M. Wong-A-Ton said:
I'm not sure I understand what the problem is. And where does the
OnSubmitRequest event handler come into play? What code do you have in there?
To close a form use Close() (see
http://msdn2.microsoft.com/en-us/library/microsoft.office.infopath.xmlform.close(VS.80).aspx)
and to close InfoPath use Application.Quit() (see
http://msdn2.microsoft.com/en-us/library/microsoft.office.infopath.application.quit(VS.80).aspx). Your form will need to have full-trust to use the latter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top