I've been following this post with some interest as I have been running into the same issue that kennebg references in his last post...
I am creating a change control form. I want users to have the ability to copy data stored in a SharePoint list into a repeating table in the main form data source and be able to edit it as necessary (changes do not need to be pushed back to the SP list).
So far, I've defined my namespace, using the sampledata.xml file:
<xd:DataConnection Name="SRM Customer Contacts">
<dfs:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-06-23T17:07:57" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003">
<dfs:dataFields>
<dfs:SRM_Customer_Contacts Customer="" Full_Name="" E-mail_Address="" Business_Phone="" Home_Phone="" Mobile_Phone="" Notes="" ID=""/>
</dfs:dataFields>
<xd:SchemaInfo LocalName="myFields" NamespaceURI="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution">
<xd:Namespaces>
<xd:Namespace LocalName="myFields" NamespaceURI="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"/>
<xd:Namespace LocalName="myFields" NamespaceURI="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"/>
<xd:Namespace LocalName="myFields" NamespaceURI="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"/>
</xd:Namespaces>
</xd:SchemaInfo>
</dfs:myFields>
</xd:DataConnection>
My Namespace definition is:
XDocument.GetDOM("SRM Customer Contacts").setProperty("SelectionNamespaces",'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-06-23T17:07:57" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
My script is:
function CTRL145::OnClick(eventObj)
{
// ensure a customer is selected
if(XDocument.DOM.selectSingleNode("/my:myFields/my:fldCustomerName").text == "")
{
// Notify the user if no customer is selected
XDocument.UI.Alert("Please select a customer before attempting to load contacts from SharePoint.");
return;
}
// Get a copy of the main DOM node
var clone = XDocument.DOM.selectSingleNode("/my:myFields/my:group7/my:grpCustomerContacts").cloneNode(true);
// clear the main DOM nodes
XDocument.DOM.selectNodes("/my:myFields/my:group7/my:grpCustomerContacts").removeAll();
// Copy nodes from 2DS to main DOM
var nodes = XDocument.GetDOM("SRM Customer Contacts").selectNodes("/dfs:myFields/dfs:dataFields/dfs:SRM_Customer_Contacts");
XDocument.UI.Alert(nodes.length); // this alert always returns 5 (which is the number of records on SharePoint)
var node;
while (node = nodes.nextNode())
{
var newContact = clone.cloneNode(true);
newContact.selectSingleNode("my:fldCustContName").text = node.selectSingleNode("Full_Name").text; XDocument.DOM.selectSingleNode("/my:myFields/my:group7").appendChild(newContact);
//XDocument.UI.Alert(node.text); //this alert is always blank
//clone.selectSingleNode("my:fldCustContName").text = node.selectSingleNode("Full_Name").text;
//XDocument.DOM.selectSingleNode("/my:myFields/my:group7/my:grpCustomerContacts").appendChild(clone.cloneNode(true));
}
}
When I preview the form, I get the following error:
Object required
File:script.js
Line:140
Which is this line of code:
newContact.selectSingleNode("my:fldCustContName").text = node.selectSingleNode("Full_Name").text;
I've been trying to get this to work, off and on, for the last two weeks. I'd really like to be able to move forward with this project, but am at this point 100% stuck. Any help is greatly appreciated...
kennebg -- sorry to hijack your thread.