Programmatically add event to SharePoint calendar using InfoPa Jsc

S

S.Y.M. Wong-A-Ton

If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
var root = XDocument.DOM;

For each variable declaration, replace "string" by "var".
string title = root.SelectSingleNode(..., ...).Value;
should be changed into
var title = root.selectSingleNode("my:...").text; <= do not use the
NamespaceManager part

XPathNavigator batch = DataSources[...].CreateNavigator();
should be changed into
var batch = XDocument.DataObjects[...].DOM;

batch.SelectSingleNode(...,...).SetValue(title);
should be changed into
batch.selectSingleNode("/Batch/...").text = title; <= do not use the
NamespaceManager part

DataConnections["Web Service Submit"].Execute();
should be changed into
XDocument.DataAdapters["Web Service Submit"].Submit();

If you get stuck, let me know.
 
V

Vman92

I modified the JScript as follows:


function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}

Now I am getting the following error:

The following error occurred:
Reference to undeclared namespace prefix: 'my'.
File:script.js
Line:11
Unspecified error

I know it has to do with declaring a namespace to reference the secondary
data source. Unfortunately, I am unfamiliar with this. Is this done within
the header of the
JScript?

--
In the absence of genuine leadership, they''''ll listen to anyone who steps
up to the microphone.


S.Y.M. Wong-A-Ton said:
If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
var root = XDocument.DOM;

For each variable declaration, replace "string" by "var".
string title = root.SelectSingleNode(..., ...).Value;
should be changed into
var title = root.selectSingleNode("my:...").text; <= do not use the
NamespaceManager part

XPathNavigator batch = DataSources[...].CreateNavigator();
should be changed into
var batch = XDocument.DataObjects[...].DOM;

batch.SelectSingleNode(...,...).SetValue(title);
should be changed into
batch.selectSingleNode("/Batch/...").text = title; <= do not use the
NamespaceManager part

DataConnections["Web Service Submit"].Execute();
should be changed into
XDocument.DataAdapters["Web Service Submit"].Submit();

If you get stuck, let me know.
---
S.Y.M. Wong-A-Ton


Vman92 said:
I have Infopath 2003 which does not have a C# code option. My user group also
has Infopath 2003 so an upgrade is out of the question. However, I have seen
some amazing code from S.Y.M. Wong A Ton to programmatically update a
Sharepoint calendar from an InfoPath form. Unfortunately, I can only use
Jscript. Does anybody know if there is similiar code in Jscript?

http://enterprise-solutions.swits.n...m-sharepoint-calendar-infopath&c=infopath2007
 
V

Vman92

I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}


Now, unfortunately, I am getting the following error which I don't understand.

'XDocument.DataAdapters.Web Service Submit' is null or not an object

File:script.js
Line:49


--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
var root = XDocument.DOM;

For each variable declaration, replace "string" by "var".
string title = root.SelectSingleNode(..., ...).Value;
should be changed into
var title = root.selectSingleNode("my:...").text; <= do not use the
NamespaceManager part

XPathNavigator batch = DataSources[...].CreateNavigator();
should be changed into
var batch = XDocument.DataObjects[...].DOM;

batch.SelectSingleNode(...,...).SetValue(title);
should be changed into
batch.selectSingleNode("/Batch/...").text = title; <= do not use the
NamespaceManager part

DataConnections["Web Service Submit"].Execute();
should be changed into
XDocument.DataAdapters["Web Service Submit"].Submit();

If you get stuck, let me know.
---
S.Y.M. Wong-A-Ton


Vman92 said:
I have Infopath 2003 which does not have a C# code option. My user group also
has Infopath 2003 so an upgrade is out of the question. However, I have seen
some amazing code from S.Y.M. Wong A Ton to programmatically update a
Sharepoint calendar from an InfoPath form. Unfortunately, I can only use
Jscript. Does anybody know if there is similiar code in Jscript?

http://enterprise-solutions.swits.n...m-sharepoint-calendar-infopath&c=infopath2007
 
S

S.Y.M. Wong-A-Ton

I found the namespace error a bit strange, since the secondary data source
does not contain any namespaces and the "my" namespace is defined by default
for the main data source. Anyway, well done sorting that out.

Regarding the "is null or not an object error": Did you create a submit data
connection to the web service and named it "Web Service Submit" (step 4)?

I've also spotted some errors in your code, for example:
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

The "endDate,endTime" isn't going to work. The string.Format("{0}T{1}Z",
endDate, endTime) you have to translate as

endDate + "T" + endTime + "Z"
---
S.Y.M. Wong-A-Ton


Vman92 said:
I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}


Now, unfortunately, I am getting the following error which I don't understand.

'XDocument.DataAdapters.Web Service Submit' is null or not an object

File:script.js
Line:49


--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
var root = XDocument.DOM;

For each variable declaration, replace "string" by "var".
string title = root.SelectSingleNode(..., ...).Value;
should be changed into
var title = root.selectSingleNode("my:...").text; <= do not use the
NamespaceManager part

XPathNavigator batch = DataSources[...].CreateNavigator();
should be changed into
var batch = XDocument.DataObjects[...].DOM;

batch.SelectSingleNode(...,...).SetValue(title);
should be changed into
batch.selectSingleNode("/Batch/...").text = title; <= do not use the
NamespaceManager part

DataConnections["Web Service Submit"].Execute();
should be changed into
XDocument.DataAdapters["Web Service Submit"].Submit();

If you get stuck, let me know.
---
S.Y.M. Wong-A-Ton


Vman92 said:
I have Infopath 2003 which does not have a C# code option. My user group also
has Infopath 2003 so an upgrade is out of the question. However, I have seen
some amazing code from S.Y.M. Wong A Ton to programmatically update a
Sharepoint calendar from an InfoPath form. Unfortunately, I can only use
Jscript. Does anybody know if there is similiar code in Jscript?

http://enterprise-solutions.swits.n...m-sharepoint-calendar-infopath&c=infopath2007
 
V

Vman92

Thanks. I think I am almost there. I was going off of #4 where it says to
'Accept the default name for the data connection'. The default name is just
'Submit'. That was what was throwing me off. I changed it to 'Web Service
Submit' and the error has gone away.

I modified the code as you had suggested and the form opens. I fill out the
form and hit the add button and nothing happens. I check the calendar on the
Sharepoint site and nothing appears. If I go onto the form and click add
multiple times in succesion, I can see it accessing a data source. So, it
seems to be trying at least. I just don't know if the data I am attempting to
pass is formatted correctly. For both the startDate and endDate I have the
field formatted as 2001-03-14. And for both the startTime and endTime I have
the field formatted as 9:46:55. The code is shown below:

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate + "T" + startTime + "Z";

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate + "T" + endTime + "Z";

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
I found the namespace error a bit strange, since the secondary data source
does not contain any namespaces and the "my" namespace is defined by default
for the main data source. Anyway, well done sorting that out.

Regarding the "is null or not an object error": Did you create a submit data
connection to the web service and named it "Web Service Submit" (step 4)?

I've also spotted some errors in your code, for example:
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

The "endDate,endTime" isn't going to work. The string.Format("{0}T{1}Z",
endDate, endTime) you have to translate as

endDate + "T" + endTime + "Z"
---
S.Y.M. Wong-A-Ton


Vman92 said:
I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}


Now, unfortunately, I am getting the following error which I don't understand.

'XDocument.DataAdapters.Web Service Submit' is null or not an object

File:script.js
Line:49


--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
var root = XDocument.DOM;

For each variable declaration, replace "string" by "var".
string title = root.SelectSingleNode(..., ...).Value;
should be changed into
var title = root.selectSingleNode("my:...").text; <= do not use the
NamespaceManager part

XPathNavigator batch = DataSources[...].CreateNavigator();
should be changed into
var batch = XDocument.DataObjects[...].DOM;

batch.SelectSingleNode(...,...).SetValue(title);
should be changed into
batch.selectSingleNode("/Batch/...").text = title; <= do not use the
NamespaceManager part

DataConnections["Web Service Submit"].Execute();
should be changed into
XDocument.DataAdapters["Web Service Submit"].Submit();

If you get stuck, let me know.
---
S.Y.M. Wong-A-Ton


:

I have Infopath 2003 which does not have a C# code option. My user group also
has Infopath 2003 so an upgrade is out of the question. However, I have seen
some amazing code from S.Y.M. Wong A Ton to programmatically update a
Sharepoint calendar from an InfoPath form. Unfortunately, I can only use
Jscript. Does anybody know if there is similiar code in Jscript?

http://enterprise-solutions.swits.n...m-sharepoint-calendar-infopath&c=infopath2007
 
S

S.Y.M. Wong-A-Ton

The format looks fine to me. You may be having a security issue. Does the
user account you are using have permission to add items to the list
pertaining to the calendar? Another thing you can do is check whether any
error messages have been logged in the Windows Event Log of the server where
SharePoint is hosted.
---
S.Y.M. Wong-A-Ton


Vman92 said:
Thanks. I think I am almost there. I was going off of #4 where it says to
'Accept the default name for the data connection'. The default name is just
'Submit'. That was what was throwing me off. I changed it to 'Web Service
Submit' and the error has gone away.

I modified the code as you had suggested and the form opens. I fill out the
form and hit the add button and nothing happens. I check the calendar on the
Sharepoint site and nothing appears. If I go onto the form and click add
multiple times in succesion, I can see it accessing a data source. So, it
seems to be trying at least. I just don't know if the data I am attempting to
pass is formatted correctly. For both the startDate and endDate I have the
field formatted as 2001-03-14. And for both the startTime and endTime I have
the field formatted as 9:46:55. The code is shown below:

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate + "T" + startTime + "Z";

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate + "T" + endTime + "Z";

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
I found the namespace error a bit strange, since the secondary data source
does not contain any namespaces and the "my" namespace is defined by default
for the main data source. Anyway, well done sorting that out.

Regarding the "is null or not an object error": Did you create a submit data
connection to the web service and named it "Web Service Submit" (step 4)?

I've also spotted some errors in your code, for example:
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

The "endDate,endTime" isn't going to work. The string.Format("{0}T{1}Z",
endDate, endTime) you have to translate as

endDate + "T" + endTime + "Z"
---
S.Y.M. Wong-A-Ton


Vman92 said:
I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}


Now, unfortunately, I am getting the following error which I don't understand.

'XDocument.DataAdapters.Web Service Submit' is null or not an object

File:script.js
Line:49


--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
var root = XDocument.DOM;

For each variable declaration, replace "string" by "var".
string title = root.SelectSingleNode(..., ...).Value;
should be changed into
var title = root.selectSingleNode("my:...").text; <= do not use the
NamespaceManager part

XPathNavigator batch = DataSources[...].CreateNavigator();
should be changed into
var batch = XDocument.DataObjects[...].DOM;

batch.SelectSingleNode(...,...).SetValue(title);
should be changed into
batch.selectSingleNode("/Batch/...").text = title; <= do not use the
NamespaceManager part

DataConnections["Web Service Submit"].Execute();
should be changed into
XDocument.DataAdapters["Web Service Submit"].Submit();

If you get stuck, let me know.
---
S.Y.M. Wong-A-Ton


:

I have Infopath 2003 which does not have a C# code option. My user group also
has Infopath 2003 so an upgrade is out of the question. However, I have seen
some amazing code from S.Y.M. Wong A Ton to programmatically update a
Sharepoint calendar from an InfoPath form. Unfortunately, I can only use
Jscript. Does anybody know if there is similiar code in Jscript?

http://enterprise-solutions.swits.n...m-sharepoint-calendar-infopath&c=infopath2007
 
V

Vman92

I am listed as owner of the Sharepoint site. So, I do have the appropriate
access level to add list items. I am working with our server team to explore
any type of server error or web service issue.

The field names for the Sharepoint site list are: Title, Location, Start
Time (which includes the date field), End Time (which includes the date
field), Description, All Day Event, Recurrence and Workspace. Are there
certain fields that absolutely must be set? And, I am not sure but I don't
believe I am setting the correct fields within the code below. Don't I have
to set the field names exactly the same as the Sharepoint list?

batch.selectSingleNode ... 'Title', 'Location', 'EventDate', 'EndDate'

--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
The format looks fine to me. You may be having a security issue. Does the
user account you are using have permission to add items to the list
pertaining to the calendar? Another thing you can do is check whether any
error messages have been logged in the Windows Event Log of the server where
SharePoint is hosted.
---
S.Y.M. Wong-A-Ton


Vman92 said:
Thanks. I think I am almost there. I was going off of #4 where it says to
'Accept the default name for the data connection'. The default name is just
'Submit'. That was what was throwing me off. I changed it to 'Web Service
Submit' and the error has gone away.

I modified the code as you had suggested and the form opens. I fill out the
form and hit the add button and nothing happens. I check the calendar on the
Sharepoint site and nothing appears. If I go onto the form and click add
multiple times in succesion, I can see it accessing a data source. So, it
seems to be trying at least. I just don't know if the data I am attempting to
pass is formatted correctly. For both the startDate and endDate I have the
field formatted as 2001-03-14. And for both the startTime and endTime I have
the field formatted as 9:46:55. The code is shown below:

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate + "T" + startTime + "Z";

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate + "T" + endTime + "Z";

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
I found the namespace error a bit strange, since the secondary data source
does not contain any namespaces and the "my" namespace is defined by default
for the main data source. Anyway, well done sorting that out.

Regarding the "is null or not an object error": Did you create a submit data
connection to the web service and named it "Web Service Submit" (step 4)?

I've also spotted some errors in your code, for example:
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

The "endDate,endTime" isn't going to work. The string.Format("{0}T{1}Z",
endDate, endTime) you have to translate as

endDate + "T" + endTime + "Z"
---
S.Y.M. Wong-A-Ton


:

I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}


Now, unfortunately, I am getting the following error which I don't understand.

'XDocument.DataAdapters.Web Service Submit' is null or not an object

File:script.js
Line:49


--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
var root = XDocument.DOM;

For each variable declaration, replace "string" by "var".
string title = root.SelectSingleNode(..., ...).Value;
should be changed into
var title = root.selectSingleNode("my:...").text; <= do not use the
NamespaceManager part

XPathNavigator batch = DataSources[...].CreateNavigator();
should be changed into
var batch = XDocument.DataObjects[...].DOM;

batch.SelectSingleNode(...,...).SetValue(title);
should be changed into
batch.selectSingleNode("/Batch/...").text = title; <= do not use the
NamespaceManager part

DataConnections["Web Service Submit"].Execute();
should be changed into
XDocument.DataAdapters["Web Service Submit"].Submit();

If you get stuck, let me know.
---
S.Y.M. Wong-A-Ton


:

I have Infopath 2003 which does not have a C# code option. My user group also
has Infopath 2003 so an upgrade is out of the question. However, I have seen
some amazing code from S.Y.M. Wong A Ton to programmatically update a
Sharepoint calendar from an InfoPath form. Unfortunately, I can only use
Jscript. Does anybody know if there is similiar code in Jscript?

http://enterprise-solutions.swits.n...m-sharepoint-calendar-infopath&c=infopath2007
 
S

S.Y.M. Wong-A-Ton

You are using SharePoint 2003, are you? I'm not sure if the field names
changed between versions 2003 and 2007, but I doubt it. By the way, what you
see on the screen is not always what is used at the back end, so the field
names might differ; you must look at the names defined in the schema for a
list and use those names instead of the names displayed on the screen. The
field names in the article are the names used in the schema of 2007.

I believe title and start date were mandatory. End date might be too, but
I'm not sure about that. The rest is optional.

I'll have to check whether I still have an InfoPath 2003 / WSS v2
environment set up. If I do, I'll try to test it out for you this weekend.
---
S.Y.M. Wong-A-Ton


Vman92 said:
I am listed as owner of the Sharepoint site. So, I do have the appropriate
access level to add list items. I am working with our server team to explore
any type of server error or web service issue.

The field names for the Sharepoint site list are: Title, Location, Start
Time (which includes the date field), End Time (which includes the date
field), Description, All Day Event, Recurrence and Workspace. Are there
certain fields that absolutely must be set? And, I am not sure but I don't
believe I am setting the correct fields within the code below. Don't I have
to set the field names exactly the same as the Sharepoint list?

batch.selectSingleNode ... 'Title', 'Location', 'EventDate', 'EndDate'

--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
The format looks fine to me. You may be having a security issue. Does the
user account you are using have permission to add items to the list
pertaining to the calendar? Another thing you can do is check whether any
error messages have been logged in the Windows Event Log of the server where
SharePoint is hosted.
---
S.Y.M. Wong-A-Ton


Vman92 said:
Thanks. I think I am almost there. I was going off of #4 where it says to
'Accept the default name for the data connection'. The default name is just
'Submit'. That was what was throwing me off. I changed it to 'Web Service
Submit' and the error has gone away.

I modified the code as you had suggested and the form opens. I fill out the
form and hit the add button and nothing happens. I check the calendar on the
Sharepoint site and nothing appears. If I go onto the form and click add
multiple times in succesion, I can see it accessing a data source. So, it
seems to be trying at least. I just don't know if the data I am attempting to
pass is formatted correctly. For both the startDate and endDate I have the
field formatted as 2001-03-14. And for both the startTime and endTime I have
the field formatted as 9:46:55. The code is shown below:

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate + "T" + startTime + "Z";

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate + "T" + endTime + "Z";

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

I found the namespace error a bit strange, since the secondary data source
does not contain any namespaces and the "my" namespace is defined by default
for the main data source. Anyway, well done sorting that out.

Regarding the "is null or not an object error": Did you create a submit data
connection to the web service and named it "Web Service Submit" (step 4)?

I've also spotted some errors in your code, for example:
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

The "endDate,endTime" isn't going to work. The string.Format("{0}T{1}Z",
endDate, endTime) you have to translate as

endDate + "T" + endTime + "Z"
---
S.Y.M. Wong-A-Ton


:

I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}


Now, unfortunately, I am getting the following error which I don't understand.

'XDocument.DataAdapters.Web Service Submit' is null or not an object

File:script.js
Line:49


--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
var root = XDocument.DOM;

For each variable declaration, replace "string" by "var".
string title = root.SelectSingleNode(..., ...).Value;
should be changed into
var title = root.selectSingleNode("my:...").text; <= do not use the
NamespaceManager part

XPathNavigator batch = DataSources[...].CreateNavigator();
should be changed into
var batch = XDocument.DataObjects[...].DOM;

batch.SelectSingleNode(...,...).SetValue(title);
should be changed into
batch.selectSingleNode("/Batch/...").text = title; <= do not use the
NamespaceManager part

DataConnections["Web Service Submit"].Execute();
should be changed into
XDocument.DataAdapters["Web Service Submit"].Submit();

If you get stuck, let me know.
---
S.Y.M. Wong-A-Ton


:

I have Infopath 2003 which does not have a C# code option. My user group also
has Infopath 2003 so an upgrade is out of the question. However, I have seen
some amazing code from S.Y.M. Wong A Ton to programmatically update a
Sharepoint calendar from an InfoPath form. Unfortunately, I can only use
Jscript. Does anybody know if there is similiar code in Jscript?

http://enterprise-solutions.swits.n...m-sharepoint-calendar-infopath&c=infopath2007
 
S

S.Y.M. Wong-A-Ton

It is weekend in my neck of the woods, so as promised, I've looked into the
issue for you.

The good news is that the solution also works with InfoPath 2003 / WSS v2.
The bad news is that the schemas of WSS v2 and WSS v3 differ. I removed the
fAllDayEvent field from the EventCAML and submitted the form, and the item
was added to the calender. With this field included, I get the same results
you got, i.e. nothing is added. The fAllDayEvent field does not exist in the
schema for WSS v2, or at least, I did not see it. The names of the other
fields are the same in both schemas.

Solution: Remove the fAllDayEvent from the EventCAML.xml file. Refresh your
data source by going to Tools > Data Connections, click Modify, click on
Resources button and remove the EventCAML resource file, then browse and add
the EventCAML.xml back into the form. Save the form and try submitting it
again.
---
S.Y.M. Wong-A-Ton


Vman92 said:
I am listed as owner of the Sharepoint site. So, I do have the appropriate
access level to add list items. I am working with our server team to explore
any type of server error or web service issue.

The field names for the Sharepoint site list are: Title, Location, Start
Time (which includes the date field), End Time (which includes the date
field), Description, All Day Event, Recurrence and Workspace. Are there
certain fields that absolutely must be set? And, I am not sure but I don't
believe I am setting the correct fields within the code below. Don't I have
to set the field names exactly the same as the Sharepoint list?

batch.selectSingleNode ... 'Title', 'Location', 'EventDate', 'EndDate'

--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
The format looks fine to me. You may be having a security issue. Does the
user account you are using have permission to add items to the list
pertaining to the calendar? Another thing you can do is check whether any
error messages have been logged in the Windows Event Log of the server where
SharePoint is hosted.
---
S.Y.M. Wong-A-Ton


Vman92 said:
Thanks. I think I am almost there. I was going off of #4 where it says to
'Accept the default name for the data connection'. The default name is just
'Submit'. That was what was throwing me off. I changed it to 'Web Service
Submit' and the error has gone away.

I modified the code as you had suggested and the form opens. I fill out the
form and hit the add button and nothing happens. I check the calendar on the
Sharepoint site and nothing appears. If I go onto the form and click add
multiple times in succesion, I can see it accessing a data source. So, it
seems to be trying at least. I just don't know if the data I am attempting to
pass is formatted correctly. For both the startDate and endDate I have the
field formatted as 2001-03-14. And for both the startTime and endTime I have
the field formatted as 9:46:55. The code is shown below:

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate + "T" + startTime + "Z";

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate + "T" + endTime + "Z";

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

I found the namespace error a bit strange, since the secondary data source
does not contain any namespaces and the "my" namespace is defined by default
for the main data source. Anyway, well done sorting that out.

Regarding the "is null or not an object error": Did you create a submit data
connection to the web service and named it "Web Service Submit" (step 4)?

I've also spotted some errors in your code, for example:
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

The "endDate,endTime" isn't going to work. The string.Format("{0}T{1}Z",
endDate, endTime) you have to translate as

endDate + "T" + endTime + "Z"
---
S.Y.M. Wong-A-Ton


:

I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}


Now, unfortunately, I am getting the following error which I don't understand.

'XDocument.DataAdapters.Web Service Submit' is null or not an object

File:script.js
Line:49


--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
var root = XDocument.DOM;

For each variable declaration, replace "string" by "var".
string title = root.SelectSingleNode(..., ...).Value;
should be changed into
var title = root.selectSingleNode("my:...").text; <= do not use the
NamespaceManager part

XPathNavigator batch = DataSources[...].CreateNavigator();
should be changed into
var batch = XDocument.DataObjects[...].DOM;

batch.SelectSingleNode(...,...).SetValue(title);
should be changed into
batch.selectSingleNode("/Batch/...").text = title; <= do not use the
NamespaceManager part

DataConnections["Web Service Submit"].Execute();
should be changed into
XDocument.DataAdapters["Web Service Submit"].Submit();

If you get stuck, let me know.
---
S.Y.M. Wong-A-Ton


:

I have Infopath 2003 which does not have a C# code option. My user group also
has Infopath 2003 so an upgrade is out of the question. However, I have seen
some amazing code from S.Y.M. Wong A Ton to programmatically update a
Sharepoint calendar from an InfoPath form. Unfortunately, I can only use
Jscript. Does anybody know if there is similiar code in Jscript?

http://enterprise-solutions.swits.n...m-sharepoint-calendar-infopath&c=infopath2007
 
V

Vman92

Checked the schema of the Sharepoint list and it appears that I am trying to
update the correct fields.
Also, saw that you updated the article "programmatically...". So, I rewrote
the InfoPath form using VB and inserted your code. Now I am getting this
error 'Expected statement - File:script.vbs - Line:7 - <p class=MsoNormal
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in">
'. I have pasted my code below. Originally the code appeared to have single
quotes ' around the style elements. This appeared to REM them out. So I
changed to double ".


'<namespacesDefinition>
XDocument.DOM.setProperty "SelectionNamespaces",
"xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-05T17:24:39"""
'</namespacesDefinition>

Sub CTRL7_5_OnClick(eventObj)

<p class=MsoNormal
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in">
<a name="OLE_LINK2"></a>
<a name="OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<code>

<span lang=EN style="font-size:10.0pt;mso-ansi-language:EN">

Dim root As XPathNavigator = MainDataSource.CreateNavigator()
</span></code></span></a>
<span style="mso-bookmark:OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<span lang=EN style="font-size:10.0pt;font-family:"Courier
New";mso-ansi-language:EN">
<br>
<br>
<code>' Retrieve the values for the calendar item
</code><br>
<code>Dim title As String = root.SelectSingleNode("my:myFields/my:title",
NamespaceManager).Value</code><br>
<code>Dim location As String =
root.SelectSingleNode("my:myFields/my:location",NamespaceManager).Value</code><br>
<code>Dim startDate As String =
root.SelectSingleNode("my:myFields/my:startDate",NamespaceManager).Value</code><br>
<code>Dim startTime As String =
root.SelectSingleNode("my:myFields/my:startTime",NamespaceManager).Value</code><br>
<code>Dim endDate As String =
root.SelectSingleNode("my:myFields/my:endDate",NamespaceManager).Value</code><br>
<code>Dim endTime As String =
root.SelectSingleNode("my:myFields/my:endTime",NamespaceManager).Value</code><br>
<br>
<code>Dim batch As XPathNavigator =
DataSources("EventCAML").CreateNavigator()</code><br>
<br>
<code>' Set the title
</code>
<br>
<code>batch.SelectSingleNode("/Batch/Method/Field[@Name='Title']",
_</code><br>
<span class=tab>NamespaceManager).SetValue(title)</span><br>
<br>
<span class=tab>' Set the location
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='Location']",_</span><br>
<span class=tab>NamespaceManager).SetValue(location)</span><br>
<br>
<span class=tab>' Set the start date
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='EventDate']",_</span><br>
<span
class=tab>NamespaceManager).SetValue(String.Format("{0}T{1}Z",startDate,
startTime))</span><br>
<br>
<span class=tab>' Set the end date
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='EndDate']",_</span><br>
<span class=tab>NamespaceManager).SetValue(String.Format("{0}T{1}Z",endDate,
endTime))</span><br>
<br>
<span class=tab>' Submit the item details to the web service to update the
calendar
</span><br>
<span class=tab>DataConnections("Web Service Submit").Execute()
</span></span></span></span>
<span style="mso-bookmark:OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<span class=tab>
<span lang=EN style="mso-ansi-language:EN">
<o:p></o:p></span></span></span></span></p>

End Sub



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
The format looks fine to me. You may be having a security issue. Does the
user account you are using have permission to add items to the list
pertaining to the calendar? Another thing you can do is check whether any
error messages have been logged in the Windows Event Log of the server where
SharePoint is hosted.
---
S.Y.M. Wong-A-Ton


Vman92 said:
Thanks. I think I am almost there. I was going off of #4 where it says to
'Accept the default name for the data connection'. The default name is just
'Submit'. That was what was throwing me off. I changed it to 'Web Service
Submit' and the error has gone away.

I modified the code as you had suggested and the form opens. I fill out the
form and hit the add button and nothing happens. I check the calendar on the
Sharepoint site and nothing appears. If I go onto the form and click add
multiple times in succesion, I can see it accessing a data source. So, it
seems to be trying at least. I just don't know if the data I am attempting to
pass is formatted correctly. For both the startDate and endDate I have the
field formatted as 2001-03-14. And for both the startTime and endTime I have
the field formatted as 9:46:55. The code is shown below:

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate + "T" + startTime + "Z";

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate + "T" + endTime + "Z";

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
I found the namespace error a bit strange, since the secondary data source
does not contain any namespaces and the "my" namespace is defined by default
for the main data source. Anyway, well done sorting that out.

Regarding the "is null or not an object error": Did you create a submit data
connection to the web service and named it "Web Service Submit" (step 4)?

I've also spotted some errors in your code, for example:
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

The "endDate,endTime" isn't going to work. The string.Format("{0}T{1}Z",
endDate, endTime) you have to translate as

endDate + "T" + endTime + "Z"
---
S.Y.M. Wong-A-Ton


:

I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}


Now, unfortunately, I am getting the following error which I don't understand.

'XDocument.DataAdapters.Web Service Submit' is null or not an object

File:script.js
Line:49


--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
var root = XDocument.DOM;

For each variable declaration, replace "string" by "var".
string title = root.SelectSingleNode(..., ...).Value;
should be changed into
var title = root.selectSingleNode("my:...").text; <= do not use the
NamespaceManager part

XPathNavigator batch = DataSources[...].CreateNavigator();
should be changed into
var batch = XDocument.DataObjects[...].DOM;

batch.SelectSingleNode(...,...).SetValue(title);
should be changed into
batch.selectSingleNode("/Batch/...").text = title; <= do not use the
NamespaceManager part

DataConnections["Web Service Submit"].Execute();
should be changed into
XDocument.DataAdapters["Web Service Submit"].Submit();

If you get stuck, let me know.
---
S.Y.M. Wong-A-Ton


:

I have Infopath 2003 which does not have a C# code option. My user group also
has Infopath 2003 so an upgrade is out of the question. However, I have seen
some amazing code from S.Y.M. Wong A Ton to programmatically update a
Sharepoint calendar from an InfoPath form. Unfortunately, I can only use
Jscript. Does anybody know if there is similiar code in Jscript?

http://enterprise-solutions.swits.n...m-sharepoint-calendar-infopath&c=infopath2007
 
S

S.Y.M. Wong-A-Ton

You were almost there; there was no need to switch to VBScript. :) Did you
try my last suggestion of removing the fAllDayEvent field from the
EventCAML.xml and "re-adding" it as a data connection? That should have
solved your problems.

The current issue you're having is because you've got HTML code interspersed
with VBScript code. If you copy code off my website, paste it into Notepad
first so that all the formatting is removed, then copy the code from Notepad
and paste it into InfoPath.
---
S.Y.M. Wong-A-Ton


Vman92 said:
Checked the schema of the Sharepoint list and it appears that I am trying to
update the correct fields.
Also, saw that you updated the article "programmatically...". So, I rewrote
the InfoPath form using VB and inserted your code. Now I am getting this
error 'Expected statement - File:script.vbs - Line:7 - <p class=MsoNormal
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in">
'. I have pasted my code below. Originally the code appeared to have single
quotes ' around the style elements. This appeared to REM them out. So I
changed to double ".


'<namespacesDefinition>
XDocument.DOM.setProperty "SelectionNamespaces",
"xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-05T17:24:39"""
'</namespacesDefinition>

Sub CTRL7_5_OnClick(eventObj)

<p class=MsoNormal
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in">
<a name="OLE_LINK2"></a>
<a name="OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<code>

<span lang=EN style="font-size:10.0pt;mso-ansi-language:EN">

Dim root As XPathNavigator = MainDataSource.CreateNavigator()
</span></code></span></a>
<span style="mso-bookmark:OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<span lang=EN style="font-size:10.0pt;font-family:"Courier
New";mso-ansi-language:EN">
<br>
<br>
<code>' Retrieve the values for the calendar item
</code><br>
<code>Dim title As String = root.SelectSingleNode("my:myFields/my:title",
NamespaceManager).Value</code><br>
<code>Dim location As String =
root.SelectSingleNode("my:myFields/my:location",NamespaceManager).Value</code><br>
<code>Dim startDate As String =
root.SelectSingleNode("my:myFields/my:startDate",NamespaceManager).Value</code><br>
<code>Dim startTime As String =
root.SelectSingleNode("my:myFields/my:startTime",NamespaceManager).Value</code><br>
<code>Dim endDate As String =
root.SelectSingleNode("my:myFields/my:endDate",NamespaceManager).Value</code><br>
<code>Dim endTime As String =
root.SelectSingleNode("my:myFields/my:endTime",NamespaceManager).Value</code><br>
<br>
<code>Dim batch As XPathNavigator =
DataSources("EventCAML").CreateNavigator()</code><br>
<br>
<code>' Set the title
</code>
<br>
<code>batch.SelectSingleNode("/Batch/Method/Field[@Name='Title']",
_</code><br>
<span class=tab>NamespaceManager).SetValue(title)</span><br>
<br>
<span class=tab>' Set the location
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='Location']",_</span><br>
<span class=tab>NamespaceManager).SetValue(location)</span><br>
<br>
<span class=tab>' Set the start date
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='EventDate']",_</span><br>
<span
class=tab>NamespaceManager).SetValue(String.Format("{0}T{1}Z",startDate,
startTime))</span><br>
<br>
<span class=tab>' Set the end date
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='EndDate']",_</span><br>
<span class=tab>NamespaceManager).SetValue(String.Format("{0}T{1}Z",endDate,
endTime))</span><br>
<br>
<span class=tab>' Submit the item details to the web service to update the
calendar
</span><br>
<span class=tab>DataConnections("Web Service Submit").Execute()
</span></span></span></span>
<span style="mso-bookmark:OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<span class=tab>
<span lang=EN style="mso-ansi-language:EN">
<o:p></o:p></span></span></span></span></p>

End Sub



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
The format looks fine to me. You may be having a security issue. Does the
user account you are using have permission to add items to the list
pertaining to the calendar? Another thing you can do is check whether any
error messages have been logged in the Windows Event Log of the server where
SharePoint is hosted.
---
S.Y.M. Wong-A-Ton


Vman92 said:
Thanks. I think I am almost there. I was going off of #4 where it says to
'Accept the default name for the data connection'. The default name is just
'Submit'. That was what was throwing me off. I changed it to 'Web Service
Submit' and the error has gone away.

I modified the code as you had suggested and the form opens. I fill out the
form and hit the add button and nothing happens. I check the calendar on the
Sharepoint site and nothing appears. If I go onto the form and click add
multiple times in succesion, I can see it accessing a data source. So, it
seems to be trying at least. I just don't know if the data I am attempting to
pass is formatted correctly. For both the startDate and endDate I have the
field formatted as 2001-03-14. And for both the startTime and endTime I have
the field formatted as 9:46:55. The code is shown below:

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate + "T" + startTime + "Z";

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate + "T" + endTime + "Z";

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

I found the namespace error a bit strange, since the secondary data source
does not contain any namespaces and the "my" namespace is defined by default
for the main data source. Anyway, well done sorting that out.

Regarding the "is null or not an object error": Did you create a submit data
connection to the web service and named it "Web Service Submit" (step 4)?

I've also spotted some errors in your code, for example:
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

The "endDate,endTime" isn't going to work. The string.Format("{0}T{1}Z",
endDate, endTime) you have to translate as

endDate + "T" + endTime + "Z"
---
S.Y.M. Wong-A-Ton


:

I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}


Now, unfortunately, I am getting the following error which I don't understand.

'XDocument.DataAdapters.Web Service Submit' is null or not an object

File:script.js
Line:49


--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

If you download the InfoPath toolkit, you can use C# code. But it should be
possible to use JScript code for this solution. I have not tested it, so you
can convert the code to JScript and test whether it works. :)

Conversion from C# to JScript shouldn't be too difficult. Here's how:

XPathNavigator root = MainDataSource.CreateNavigator();
should be changed into
 
V

Vman92

Holy Cow. It works. I can't thank you enough for all of your help. This was
something that I have been trying to understand and get working for almost 2
months now. I really apreciate your help.

Sorry I missed your second post on 2/23/2007. That would have saved me some
time. Oh well, I really enjoy learning new stuff and writing code. Now at
least I have a pretty good understanding of the issues. I can start working
on extending the functionality.

--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
You were almost there; there was no need to switch to VBScript. :) Did you
try my last suggestion of removing the fAllDayEvent field from the
EventCAML.xml and "re-adding" it as a data connection? That should have
solved your problems.

The current issue you're having is because you've got HTML code interspersed
with VBScript code. If you copy code off my website, paste it into Notepad
first so that all the formatting is removed, then copy the code from Notepad
and paste it into InfoPath.
---
S.Y.M. Wong-A-Ton


Vman92 said:
Checked the schema of the Sharepoint list and it appears that I am trying to
update the correct fields.
Also, saw that you updated the article "programmatically...". So, I rewrote
the InfoPath form using VB and inserted your code. Now I am getting this
error 'Expected statement - File:script.vbs - Line:7 - <p class=MsoNormal
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in">
'. I have pasted my code below. Originally the code appeared to have single
quotes ' around the style elements. This appeared to REM them out. So I
changed to double ".


'<namespacesDefinition>
XDocument.DOM.setProperty "SelectionNamespaces",
"xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-05T17:24:39"""
'</namespacesDefinition>

Sub CTRL7_5_OnClick(eventObj)

<p class=MsoNormal
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in">
<a name="OLE_LINK2"></a>
<a name="OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<code>

<span lang=EN style="font-size:10.0pt;mso-ansi-language:EN">

Dim root As XPathNavigator = MainDataSource.CreateNavigator()
</span></code></span></a>
<span style="mso-bookmark:OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<span lang=EN style="font-size:10.0pt;font-family:"Courier
New";mso-ansi-language:EN">
<br>
<br>
<code>' Retrieve the values for the calendar item
</code><br>
<code>Dim title As String = root.SelectSingleNode("my:myFields/my:title",
NamespaceManager).Value</code><br>
<code>Dim location As String =
root.SelectSingleNode("my:myFields/my:location",NamespaceManager).Value</code><br>
<code>Dim startDate As String =
root.SelectSingleNode("my:myFields/my:startDate",NamespaceManager).Value</code><br>
<code>Dim startTime As String =
root.SelectSingleNode("my:myFields/my:startTime",NamespaceManager).Value</code><br>
<code>Dim endDate As String =
root.SelectSingleNode("my:myFields/my:endDate",NamespaceManager).Value</code><br>
<code>Dim endTime As String =
root.SelectSingleNode("my:myFields/my:endTime",NamespaceManager).Value</code><br>
<br>
<code>Dim batch As XPathNavigator =
DataSources("EventCAML").CreateNavigator()</code><br>
<br>
<code>' Set the title
</code>
<br>
<code>batch.SelectSingleNode("/Batch/Method/Field[@Name='Title']",
_</code><br>
<span class=tab>NamespaceManager).SetValue(title)</span><br>
<br>
<span class=tab>' Set the location
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='Location']",_</span><br>
<span class=tab>NamespaceManager).SetValue(location)</span><br>
<br>
<span class=tab>' Set the start date
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='EventDate']",_</span><br>
<span
class=tab>NamespaceManager).SetValue(String.Format("{0}T{1}Z",startDate,
startTime))</span><br>
<br>
<span class=tab>' Set the end date
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='EndDate']",_</span><br>
<span class=tab>NamespaceManager).SetValue(String.Format("{0}T{1}Z",endDate,
endTime))</span><br>
<br>
<span class=tab>' Submit the item details to the web service to update the
calendar
</span><br>
<span class=tab>DataConnections("Web Service Submit").Execute()
</span></span></span></span>
<span style="mso-bookmark:OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<span class=tab>
<span lang=EN style="mso-ansi-language:EN">
<o:p></o:p></span></span></span></span></p>

End Sub



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
The format looks fine to me. You may be having a security issue. Does the
user account you are using have permission to add items to the list
pertaining to the calendar? Another thing you can do is check whether any
error messages have been logged in the Windows Event Log of the server where
SharePoint is hosted.
---
S.Y.M. Wong-A-Ton


:

Thanks. I think I am almost there. I was going off of #4 where it says to
'Accept the default name for the data connection'. The default name is just
'Submit'. That was what was throwing me off. I changed it to 'Web Service
Submit' and the error has gone away.

I modified the code as you had suggested and the form opens. I fill out the
form and hit the add button and nothing happens. I check the calendar on the
Sharepoint site and nothing appears. If I go onto the form and click add
multiple times in succesion, I can see it accessing a data source. So, it
seems to be trying at least. I just don't know if the data I am attempting to
pass is formatted correctly. For both the startDate and endDate I have the
field formatted as 2001-03-14. And for both the startTime and endTime I have
the field formatted as 9:46:55. The code is shown below:

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate + "T" + startTime + "Z";

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate + "T" + endTime + "Z";

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

I found the namespace error a bit strange, since the secondary data source
does not contain any namespaces and the "my" namespace is defined by default
for the main data source. Anyway, well done sorting that out.

Regarding the "is null or not an object error": Did you create a submit data
connection to the web service and named it "Web Service Submit" (step 4)?

I've also spotted some errors in your code, for example:
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

The "endDate,endTime" isn't going to work. The string.Format("{0}T{1}Z",
endDate, endTime) you have to translate as

endDate + "T" + endTime + "Z"
---
S.Y.M. Wong-A-Ton


:

I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}


Now, unfortunately, I am getting the following error which I don't understand.

'XDocument.DataAdapters.Web Service Submit' is null or not an object

File:script.js
Line:49
 
S

steve

Checked the schema of the Sharepoint list and it appears that I am trying to
update the correct fields.

how does one check the schema of the SharePoint list?

thanks

steve
 
S

S.Y.M. Wong-A-Ton

No worries. Glad I could help.
---
S.Y.M. Wong-A-Ton


Vman92 said:
Holy Cow. It works. I can't thank you enough for all of your help. This was
something that I have been trying to understand and get working for almost 2
months now. I really apreciate your help.

Sorry I missed your second post on 2/23/2007. That would have saved me some
time. Oh well, I really enjoy learning new stuff and writing code. Now at
least I have a pretty good understanding of the issues. I can start working
on extending the functionality.

--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


S.Y.M. Wong-A-Ton said:
You were almost there; there was no need to switch to VBScript. :) Did you
try my last suggestion of removing the fAllDayEvent field from the
EventCAML.xml and "re-adding" it as a data connection? That should have
solved your problems.

The current issue you're having is because you've got HTML code interspersed
with VBScript code. If you copy code off my website, paste it into Notepad
first so that all the formatting is removed, then copy the code from Notepad
and paste it into InfoPath.
---
S.Y.M. Wong-A-Ton


Vman92 said:
Checked the schema of the Sharepoint list and it appears that I am trying to
update the correct fields.
Also, saw that you updated the article "programmatically...". So, I rewrote
the InfoPath form using VB and inserted your code. Now I am getting this
error 'Expected statement - File:script.vbs - Line:7 - <p class=MsoNormal
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in">
'. I have pasted my code below. Originally the code appeared to have single
quotes ' around the style elements. This appeared to REM them out. So I
changed to double ".


'<namespacesDefinition>
XDocument.DOM.setProperty "SelectionNamespaces",
"xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-05T17:24:39"""
'</namespacesDefinition>

Sub CTRL7_5_OnClick(eventObj)

<p class=MsoNormal
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in">
<a name="OLE_LINK2"></a>
<a name="OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<code>

<span lang=EN style="font-size:10.0pt;mso-ansi-language:EN">

Dim root As XPathNavigator = MainDataSource.CreateNavigator()
</span></code></span></a>
<span style="mso-bookmark:OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<span lang=EN style="font-size:10.0pt;font-family:"Courier
New";mso-ansi-language:EN">
<br>
<br>
<code>' Retrieve the values for the calendar item
</code><br>
<code>Dim title As String = root.SelectSingleNode("my:myFields/my:title",
NamespaceManager).Value</code><br>
<code>Dim location As String =
root.SelectSingleNode("my:myFields/my:location",NamespaceManager).Value</code><br>
<code>Dim startDate As String =
root.SelectSingleNode("my:myFields/my:startDate",NamespaceManager).Value</code><br>
<code>Dim startTime As String =
root.SelectSingleNode("my:myFields/my:startTime",NamespaceManager).Value</code><br>
<code>Dim endDate As String =
root.SelectSingleNode("my:myFields/my:endDate",NamespaceManager).Value</code><br>
<code>Dim endTime As String =
root.SelectSingleNode("my:myFields/my:endTime",NamespaceManager).Value</code><br>
<br>
<code>Dim batch As XPathNavigator =
DataSources("EventCAML").CreateNavigator()</code><br>
<br>
<code>' Set the title
</code>
<br>
<code>batch.SelectSingleNode("/Batch/Method/Field[@Name='Title']",
_</code><br>
<span class=tab>NamespaceManager).SetValue(title)</span><br>
<br>
<span class=tab>' Set the location
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='Location']",_</span><br>
<span class=tab>NamespaceManager).SetValue(location)</span><br>
<br>
<span class=tab>' Set the start date
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='EventDate']",_</span><br>
<span
class=tab>NamespaceManager).SetValue(String.Format("{0}T{1}Z",startDate,
startTime))</span><br>
<br>
<span class=tab>' Set the end date
</span><br>
<span
class=tab>batch.SelectSingleNode("/Batch/Method/Field[@Name='EndDate']",_</span><br>
<span class=tab>NamespaceManager).SetValue(String.Format("{0}T{1}Z",endDate,
endTime))</span><br>
<br>
<span class=tab>' Submit the item details to the web service to update the
calendar
</span><br>
<span class=tab>DataConnections("Web Service Submit").Execute()
</span></span></span></span>
<span style="mso-bookmark:OLE_LINK1">
<span style="mso-bookmark:OLE_LINK2">
<span class=tab>
<span lang=EN style="mso-ansi-language:EN">
<o:p></o:p></span></span></span></span></p>

End Sub



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

The format looks fine to me. You may be having a security issue. Does the
user account you are using have permission to add items to the list
pertaining to the calendar? Another thing you can do is check whether any
error messages have been logged in the Windows Event Log of the server where
SharePoint is hosted.
---
S.Y.M. Wong-A-Ton


:

Thanks. I think I am almost there. I was going off of #4 where it says to
'Accept the default name for the data connection'. The default name is just
'Submit'. That was what was throwing me off. I changed it to 'Web Service
Submit' and the error has gone away.

I modified the code as you had suggested and the form opens. I fill out the
form and hit the add button and nothing happens. I check the calendar on the
Sharepoint site and nothing appears. If I go onto the form and click add
multiple times in succesion, I can see it accessing a data source. So, it
seems to be trying at least. I just don't know if the data I am attempting to
pass is formatted correctly. For both the startDate and endDate I have the
field formatted as 2001-03-14. And for both the startTime and endTime I have
the field formatted as 9:46:55. The code is shown below:

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate + "T" + startTime + "Z";

// Set the end date
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate + "T" + endTime + "Z";

// Submit the item details to the web service to update the calendar
XDocument.DataAdapters["Web Service Submit"].Submit();
}



--
In the absence of genuine leadership, they''''''''ll listen to anyone who
steps up to the microphone.


:

I found the namespace error a bit strange, since the secondary data source
does not contain any namespaces and the "my" namespace is defined by default
for the main data source. Anyway, well done sorting that out.

Regarding the "is null or not an object error": Did you create a submit data
connection to the web service and named it "Web Service Submit" (step 4)?

I've also spotted some errors in your code, for example:
batch.selectSingleNode("/Batch/Method/Field[@Name='EndDate']").text =
endDate, endTime;

The "endDate,endTime" isn't going to work. The string.Format("{0}T{1}Z",
endDate, endTime) you have to translate as

endDate + "T" + endTime + "Z"
---
S.Y.M. Wong-A-Ton


:

I discovered the problem was that I had deleted the code initially created by
InfoPath in order to see if I could change the language type to C#.
Afterwards I discovered that I could not. Now I have re-created the form and
the InfoPath created code is atop the code behind page.

/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-19T15:10:37"');
//</namespacesDefinition>

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL7_5::OnClick(eventObj)
{
var root = XDocument.DOM;

// Retrieve the values for the calendar item
var title = root.selectSingleNode("my:myFields/my:title").text;
var location = root.selectSingleNode("my:myFields/my:location").text;
var startDate = root.selectSingleNode("my:myFields/my:startDate").text;
var startTime = root.selectSingleNode("my:myFields/my:startTime").text;
var endDate = root.selectSingleNode("my:myFields/my:endDate").text;
var endTime = root.selectSingleNode("my:myFields/my:endTime").text;

var batch = XDocument.DataObjects["EventCAML"].DOM;

// Set the title
batch.selectSingleNode("/Batch/Method/Field[@Name='Title']").text = title;

// Set the location
batch.selectSingleNode("/Batch/Method/Field[@Name='Location']").text =
location;

// Set the start date
batch.selectSingleNode("/Batch/Method/Field[@Name='EventDate']").text =
startDate, startTime;

// Set the end date
 
S

S.Y.M. Wong-A-Ton

This is a great question for the SharePoint guys! Have you tried asking them?

I know of two ways:
1. In code while retrieving a list and debugging its columns. This method
works well if you created your own custom list.
2. By looking at the XML file that defines a schema for a list in one of the
subdirectories of the famous "web server extensions" directory that
SharePoint uses; sorry I do not know the path by heart. This method works
well for standard lists.
 
B

buziboy

Wong,
I've been working with your tutorial 2007 today on MOSS 2007, InfoPath
2007 on a dev server I admin. This is a Forms Services app and I could
really use your help.

It seems like the C# cannot see my data connection, though the spelling is
fine.

Object reference not set to an instance of an object.

System.NullReferenceException: Object reference not set to an instance of an
object.
at Orders.FormCode.customSubmit_Clicked(Object sender, ClickedEventArgs e)
at
Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.<>c__DisplayClass6.<>c__DisplayClass8.<add_Clicked>b__1()
at
Microsoft.Office.InfoPath.Server.Util.DocumentReliability.InvokeBusinessLogic(Thunk thunk)
at
Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.<>c__DisplayClass6.<add_Clicked>b__0(Object sender, ClickedEventArgs e)
at
Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.FireClickedEvent(Object sender, ClickedEventArgs args)
at
Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonFormCode.<>c__DisplayClass2.<>c__DisplayClass5.<Click>b__1()
at
Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.CallFormCodeWithExceptionHandling(UserMessages userMessages, OMCall d)

An entry has been added to the Windows event log of the server.
Log ID:5337

Relevant code:
public void customSubmit_Clicked(object sender, ClickedEventArgs e)
{
// Write your code here.
XPathNavigator root = MainDataSource.CreateNavigator();
string title =
root.SelectSingleNode("my:myFields/my:itemchoice", NamespaceManager).Value;
string orderID = root.SelectSingleNode("my:myFields/my:Title",
NamespaceManager).Value;
string quOrdered =
root.SelectSingleNode("my:myFields/my:itemquantity", NamespaceManager).Value;

XPathNavigator batch =
DataSources["list2CAML"].CreateNavigator(); ß--------- CHOKES, though this
is accurately named.
// batch.SelectSingleNode("/Batch/Method/Field[@Name='Title']",
NamespaceManager).SetValue(orderID);
// batch.SelectSingleNode("/Batch/Method/Field[@Name='Order
ID']", NamespaceManager).SetValue(orderID);
// batch.SelectSingleNode("/Batch/Method/Field[@Name='Quantity
Ordered']", NamespaceManager).SetValue(quOrdered);

// DataConnections["List2submit"].Execute();

}

CAML file:
<?xml version="1.0" encoding="UTF-8" ?>
<Batch>
<Method ID="1" Cmd="New">
<Field Name="Title"/>
<Field Name="Order_x0020_ID"/>
<Field Name="Quantity_x0020_Ordered"/>
</Method>
</Batch>

Much appreciated.
 
L

liam

Hi, Please can yo uhelp me ....

I get this error -


System.Security.SecurityException
Request failed.
at Microsoft.Office.InfoPath.MsxmlNavigator.IsValidNode(MsxmlNode test)
at Microsoft.Office.InfoPath.MsxmlNavigator.MoveToFirstChild()
at MS.Internal.Xml.XPath.XPathChildIterator.MoveNext()
at MS.Internal.Xml.XPath.ChildrenQuery.Advance()
at MS.Internal.Xml.XPath.ChildrenQuery.Advance()
at MS.Internal.Xml.XPath.XPathSelectionIterator.MoveNext()
at System.Xml.XPath.XPathNavigator.SelectSingleNode(XPathExpression
expression)
at System.Xml.XPath.XPathNavigator.SelectSingleNode(String xpath,
IXmlNamespaceResolver resolver)
at Cal.FormCode.CTRL7_5_Clicked(Object sender, ClickedEventArgs e)
at
Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
at
Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)




I have the correct lists.asmx any everything!
Can you help please???
 
L

liam

Hi, please can you help

I get this error -


System.Security.SecurityException
Request failed.
at Microsoft.Office.InfoPath.MsxmlNavigator.IsValidNode(MsxmlNode test)
at Microsoft.Office.InfoPath.MsxmlNavigator.MoveToFirstChild()
at MS.Internal.Xml.XPath.XPathChildIterator.MoveNext()
at MS.Internal.Xml.XPath.ChildrenQuery.Advance()
at MS.Internal.Xml.XPath.ChildrenQuery.Advance()
at MS.Internal.Xml.XPath.XPathSelectionIterator.MoveNext()
at System.Xml.XPath.XPathNavigator.SelectSingleNode(XPathExpression
expression)
at System.Xml.XPath.XPathNavigator.SelectSingleNode(String xpath,
IXmlNamespaceResolver resolver)
at Cal.FormCode.CTRL7_5_Clicked(Object sender, ClickedEventArgs e)
at
Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
at
Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)




I have the correct lists.asmx and everything
Can you help please???
 

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