Object Required?

B

Bromley

I get a message saying "Object Required line 42" when I run the function
below... line 42 is the beginning of the if statement...
I am admittedly not familiar with the Infopath object model...
This code was taken from this discussion group, and I have tried to adapt it
to connect to my database and secondary table... FYI... the Implementations
tabel and the Tasks table are part of my main database connection and are in
access... Task master is a secondary connection to the same database.

function CTRL83_7::OnClick(eventObj)
{
//Get a reference to the Table1 data connection
var objTable1DOM = XDocument.GetDOM("TaskMaster");


//Set the SelectionNamespaces property of the Table1 data connection to
walk the DOM
objTable1DOM.setProperty("SelectionNamespaces",
'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"
' +
'xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"');

//Get the selected items
var objSelectedItems =
objTable1DOM.selectNodes("//dfs:myFields/dfs:dataFields/d:TaskMaster[@Selected= 'True']");

//Loop through the selected items
for(i=0;i<=objSelectedItems.length -1;i++)
{
//See if the first record in the destination Repeating Table is blan
if(XDocument.DOM.selectSingleNode("//my:Implementations/my:Tasks/my:Item").text == "")

XDocument.DOM.selectSingleNode("//my:Implementations/my:Tasks/my:Item").text = objSelectedItems(i).attributes(1).text;
}
else
{
//Add a new row
XDocument.View.ExecuteAction("xCollection::insert", "Tasks_23");
//Get a reference to that new row
var objNewItem =
XDocument.DOM.selectSingleNode("//my:Implementations/my:Tasks[last()]/my:Item");
//Set the text of the field
objNewItem.text = objSelectedItems(i).attributes(1).text;
}
}


}
 
S

S.Y.M. Wong-A-Ton

In 9 out of 10 cases "Object required" errors are due to incorrect XPath
expressions. Double-check that you've got the correct XPath expression for
the XML node.
 
B

Bromley

You are 100% correct...
After pulling the rest of my hair out the correct statement is:
if(XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Implementations/d:Tasks/@Item").text == "")

Thanks for your reply!!!
Best,
Bromley

S.Y.M. Wong-A-Ton said:
In 9 out of 10 cases "Object required" errors are due to incorrect XPath
expressions. Double-check that you've got the correct XPath expression for
the XML node.
---
S.Y.M. Wong-A-Ton


Bromley said:
I get a message saying "Object Required line 42" when I run the function
below... line 42 is the beginning of the if statement...
I am admittedly not familiar with the Infopath object model...
This code was taken from this discussion group, and I have tried to adapt it
to connect to my database and secondary table... FYI... the Implementations
tabel and the Tasks table are part of my main database connection and are in
access... Task master is a secondary connection to the same database.

function CTRL83_7::OnClick(eventObj)
{
//Get a reference to the Table1 data connection
var objTable1DOM = XDocument.GetDOM("TaskMaster");


//Set the SelectionNamespaces property of the Table1 data connection to
walk the DOM
objTable1DOM.setProperty("SelectionNamespaces",
'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"
' +
'xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"');

//Get the selected items
var objSelectedItems =
objTable1DOM.selectNodes("//dfs:myFields/dfs:dataFields/d:TaskMaster[@Selected= 'True']");

//Loop through the selected items
for(i=0;i<=objSelectedItems.length -1;i++)
{
//See if the first record in the destination Repeating Table is blank
if(XDocument.DOM.selectSingleNode("//my:Implementations/my:Tasks/my:Item").text == "")
{
XDocument.DOM.selectSingleNode("//my:Implementations/my:Tasks/my:Item").text = objSelectedItems(i).attributes(1).text;
}
else
{
//Add a new row
XDocument.View.ExecuteAction("xCollection::insert", "Tasks_23");
//Get a reference to that new row
var objNewItem =
XDocument.DOM.selectSingleNode("//my:Implementations/my:Tasks[last()]/my:Item");
//Set the text of the field
objNewItem.text = objSelectedItems(i).attributes(1).text;
}
}


}
 

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