Just so that I understand you right...
I have changed the top 3 lines to this.
XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:my="http://www.w3.org/2001/XMLSchema-instance"');
var Namespaces = 'xmlns:my="http://www.w3.org/2001/XMLSchema-instance"';
XDocument.DataObjects["MatterBasicInfo"].DOM.setProperty("SelectionNamespaces", Namespaces);
I need to physically type this in once I have created a new button with the below code? I only ask this because, I just basically pasted all of this once I deleted what was there and I still get the error about this line.
var field1 = XDocument.DOM.selectSingleNode("/my:myFields/my:field1");
Code:
function CTRL1219::OnClick(eventObj)
{
if(RunQuery())
{
CopyResults();
}
}
function RunQuery()
{
// select the field to be queried
var field1 = XDocument.DOM.selectSingleNode("/my:myFields/my:field1");
// make sure the field is non-empty
if(field1.text.length > 0)
{
var dc = XDocument.DataObjects["x"].QueryAdapter;
// construct the SQL Query
dc.Command = "SELECT * FROM [x] WHERE [x] = '" + field1.text + "'";
dc.Query();
// return true if the query was successful
return true;
}
else
{
XDocument.UI.Alert("You must enter a value before querying!");
// return false because the query was not performed
return false;
}
}
function CopyResults()
{
// store the names of the columns in an array
var columnNames = ["x", "x", "x", "x", "x", "x_x", "x"];
// get a reference to the node where the results will be placed in the main data source
var dataFields = XDocument.DOM.selectSingleNode("/my:myFields/my:QueryResults");
// get a reference to the node with the query results in the secondary data source
var queryDataFields = XDocument.DataObjects["x"].DOM.selectSingleNode("/dfs:myFields/dfs:dataFields");
// clear out the children of the QueryResults node in the main DOM
while(dataFields.hasChildNodes())
{
dataFields.removeChild(dataFields.childNodes[0]);
}
// select all of the result rows from the query
var queryRows = queryDataFields.selectNodes("*");
// iterate through the query result rows and copy them over
for(var i = 0; i < queryRows.length; i++)
{
var queryRow = queryRows[i];
// create an opening my:ResultRow tag with the requisite namespaces
var nodeString = "<my:ResultRow "+ Namespaces +">";
// iterate through the column names and add a node to my:ResultRow for each one
for(var colNum in columnNames)
{
// get the column name from the array
var colName = columnNames[colNum];
// retrieve the column's value from the query row node
var colValue = queryRow.attributes.getNamedItem(colName).nodeValue;
// construct a node string for the column's node and append it to the
// my:ResultRow node string we are constructing
nodeString += "<my:" + colName+ ">" + colValue + "</my:" + colName + ">";
}
// close the my:ResultRow node
nodeString += "</my:ResultRow>";
// create a node from the string and append it to my:QueryResults
dataFields.appendChild(CreateNode(nodeString));
}
}
function CreateNode(nodeString)
{
var node = XDocument.CreateDOM();
node.loadXML(nodeString);
return node.documentElement;
}