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
></o
></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