Retrieve SEcondary Data into Main Database

O

oakridge

Is there anyway to populate the main database of the form which is in a
repeating table with repeating data from a secondary source. I have
successfully done this with drop down boxes to return only one field. I now
need to be able to return multiple records and put them into the main
database to be submitted out to SQL. Thanks in advance.
 
M

Michelle

In short - yes.

The following code goes through a secondary data source and creates a task
node in the main dom with child nodes for each attribute in the secondary DOM
task node. This should give you a starting point to adjust for your own
needs.

Michelle

// get task node from main data source to clone
DOMNode ndTask =
(DOMNode)thisXDocument.DOM.selectSingleNode("/my:myFields/my:dataFields/my:Tasks");

// create a node in the main data source for each task item
foreach (DOMNode nd in ndTasks)
{
DOMNode newNode = (DOMNode)ndTask.cloneNode(true);

// populate the child elements of the new task node
for (int i = 0; i < nd.attributes.length; i++)
{
string ndValue = nd.attributes.nodeValue.ToString();

switch (nd.attributes.nodeName.ToString())
{
case "Title":
newNode.selectSingleNode("/my:Title").text = ndValue;
break;
case "Priority":
newNode.selectSingleNode("/my:priority").text = ndValue;
break;
case "Status":
newNode.selectSingleNode("/my:Status").text = ndValue;
break;
case "__Complete":
newNode.selectSingleNode("/my:percentageComplete").text = ndValue;
break;
case "Assigned_To":
newNode.selectSingleNode("/my:AssignedTo").text = ndValue;
break;
case "Due_Date":
newNode.selectSingleNode("/my:DueDate").text = ndValue;
break;
default:
break;
}
}

//append the new task node
thisXDocument.DOM.childNodes[3].childNodes[1].appendChild(newNode);
}
 
O

oakridge

Michelle:

As I mentioned I know little about scripting. I made an attempt to emulate
your code using the two tables BOM REPAIR (secondary data source) and
PARLEVEL-BOM (main datasource) using jscript as the scripting language. I am
only importing one field in this example to see if it works.

Below are the results:

function XDocument::OnLoad(eventObj)
{
// get task node from main data source to clone

DOMNode ndTask =
(DOMNode)thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:BOMREPAIR");

// create a node in the main data source for each item
foreach (DOMNode nd in ndTasks)
{
DOMNode newNode = (DOMNode)ndTask.cloneNode(true);

// populate the child elements of the new task node
for (int i = 0; i < nd.attributes.length; i++)
{
string ndValue = nd.attributes.nodeValue.ToString();

switch (nd.attributes.nodeName.ToString())
{
case "BOM-PARENT"
newNode.selectSingleNode("/dfs:myFields/dfs:dataFields/d:/PARLEVEL-RBOM@RBOM-PARENT).text = ndValue;
break;
default:
break;
}
}

//append the new task node
thisXDocument.DOM.childNodes[3].childNodes[1].appendChild(newNode);

}

}
When I try to preview the form, I receiving an error on the first line of
code stating that a ";" is expected. Any help would be appreciated.

Thanks.

Ann Compton

Michelle said:
In short - yes.

The following code goes through a secondary data source and creates a task
node in the main dom with child nodes for each attribute in the secondary DOM
task node. This should give you a starting point to adjust for your own
needs.

Michelle

// get task node from main data source to clone
DOMNode ndTask =
(DOMNode)thisXDocument.DOM.selectSingleNode("/my:myFields/my:dataFields/my:Tasks");

// create a node in the main data source for each task item
foreach (DOMNode nd in ndTasks)
{
DOMNode newNode = (DOMNode)ndTask.cloneNode(true);

// populate the child elements of the new task node
for (int i = 0; i < nd.attributes.length; i++)
{
string ndValue = nd.attributes.nodeValue.ToString();

switch (nd.attributes.nodeName.ToString())
{
case "Title":
newNode.selectSingleNode("/my:Title").text = ndValue;
break;
case "Priority":
newNode.selectSingleNode("/my:priority").text = ndValue;
break;
case "Status":
newNode.selectSingleNode("/my:Status").text = ndValue;
break;
case "__Complete":
newNode.selectSingleNode("/my:percentageComplete").text = ndValue;
break;
case "Assigned_To":
newNode.selectSingleNode("/my:AssignedTo").text = ndValue;
break;
case "Due_Date":
newNode.selectSingleNode("/my:DueDate").text = ndValue;
break;
default:
break;
}
}

//append the new task node
thisXDocument.DOM.childNodes[3].childNodes[1].appendChild(newNode);
}
oakridge said:
Is there anyway to populate the main database of the form which is in a
repeating table with repeating data from a secondary source. I have
successfully done this with drop down boxes to return only one field. I now
need to be able to return multiple records and put them into the main
database to be submitted out to SQL. Thanks in advance.
 

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