Autopopulating a Repeating Section

B

BethA

I am plugging away at autopopulating some fields of a repeating section
(including BriefDescription) given an item number, using the OnAfterChange
event for the item number. I started out using a secondary data source (a
view on SQL server) and couldn't get that to work, but got some help with
using ADO.net to access SQL server and get the data I need.

It works great for the first item in the section, but when a second item is
added, the fields in the first item are populated instead of in the second
item. That's exactly what I was telling it to do since I accessed the nodes
in this way:

Dim fDescNode As IXMLDOMNode =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:RequestedSample/my:BriefDescription")

So every time it is getting the first node in the repeated section. How do I
tell it to get the node which matches the ItemNumber that has just been
updated?

I hope this makes sense, because I'm learning XML as I go along!

Another question that just came up is: why doesn't my event handler happen
when I publish the form and fill it in from the published form? It works when
I'm previewing in InfoPath.

Thanks,
BethA
 
F

Franck Dauché

Hi Beth,

You can target the nth item in your section using code such as:
IXMLDOMNode oNode =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:group1/my:group2[n]/my:field1");

Hope that it helps.

Regards,

Franck Dauché
 
B

BethA

How do I tell what n is, given that I know which node triggered the event,
but not where it is in the group?

Thanks,
BethA

Franck Dauché said:
Hi Beth,

You can target the nth item in your section using code such as:
IXMLDOMNode oNode =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:group1/my:group2[n]/my:field1");

Hope that it helps.

Regards,

Franck Dauché


BethA said:
I am plugging away at autopopulating some fields of a repeating section
(including BriefDescription) given an item number, using the OnAfterChange
event for the item number. I started out using a secondary data source (a
view on SQL server) and couldn't get that to work, but got some help with
using ADO.net to access SQL server and get the data I need.

It works great for the first item in the section, but when a second item is
added, the fields in the first item are populated instead of in the second
item. That's exactly what I was telling it to do since I accessed the nodes
in this way:

Dim fDescNode As IXMLDOMNode =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:RequestedSample/my:BriefDescription")

So every time it is getting the first node in the repeated section. How do I
tell it to get the node which matches the ItemNumber that has just been
updated?

I hope this makes sense, because I'm learning XML as I go along!

Another question that just came up is: why doesn't my event handler happen
when I publish the form and fill it in from the published form? It works when
I'm previewing in InfoPath.

Thanks,
BethA
 
F

Franck Dauché

Hi Beth,

Why don't you loop through your nodes and put the values that you need:
IXMLDOMNodeList oNodeList =
thisXDocument.DOM.selectNodes("my:myFields/my:group1/my:group2");
if (oNodeList.length>0)
{
foreach (IXMLDOMNode oN in oNodeList)
{
if( oN.nodeType == DOMNodeType.NODE_ELEMENT )
{
IXMLDOMNode oField = oN.selectSingleNode("my:field1");
oField.text = "test"; //<-- Put your value here
}
}
}

Regards,

Franck Dauché


BethA said:
How do I tell what n is, given that I know which node triggered the event,
but not where it is in the group?

Thanks,
BethA

Franck Dauché said:
Hi Beth,

You can target the nth item in your section using code such as:
IXMLDOMNode oNode =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:group1/my:group2[n]/my:field1");

Hope that it helps.

Regards,

Franck Dauché


BethA said:
I am plugging away at autopopulating some fields of a repeating section
(including BriefDescription) given an item number, using the OnAfterChange
event for the item number. I started out using a secondary data source (a
view on SQL server) and couldn't get that to work, but got some help with
using ADO.net to access SQL server and get the data I need.

It works great for the first item in the section, but when a second item is
added, the fields in the first item are populated instead of in the second
item. That's exactly what I was telling it to do since I accessed the nodes
in this way:

Dim fDescNode As IXMLDOMNode =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:RequestedSample/my:BriefDescription")

So every time it is getting the first node in the repeated section. How do I
tell it to get the node which matches the ItemNumber that has just been
updated?

I hope this makes sense, because I'm learning XML as I go along!

Another question that just came up is: why doesn't my event handler happen
when I publish the form and fill it in from the published form? It works when
I'm previewing in InfoPath.

Thanks,
BethA
 
B

BethA

Thanks Franck - It works! I just had to add a condition to the if statement
to make sure that the refNumber field of the oNode matched the refnumber that
caused the OnAfterChange event to occur. I'm not sure if I need the
oNode.nodeType = DOMNodeType.NODE_ELEMENT part because it seemed that every
node had that nodeType.

I think the problem with the published form not working was because it was
published on the network. Everything seems to work fine from my hard drive.
That's a question we have to talk about next week with CIS :)

BethA
Franck Dauché said:
Hi Beth,

Why don't you loop through your nodes and put the values that you need:
IXMLDOMNodeList oNodeList =
thisXDocument.DOM.selectNodes("my:myFields/my:group1/my:group2");
if (oNodeList.length>0)
{
foreach (IXMLDOMNode oN in oNodeList)
{
if( oN.nodeType == DOMNodeType.NODE_ELEMENT )
{
IXMLDOMNode oField = oN.selectSingleNode("my:field1");
oField.text = "test"; //<-- Put your value here
}
}
}

Regards,

Franck Dauché


BethA said:
How do I tell what n is, given that I know which node triggered the event,
but not where it is in the group?

Thanks,
BethA

Franck Dauché said:
Hi Beth,

You can target the nth item in your section using code such as:
IXMLDOMNode oNode =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:group1/my:group2[n]/my:field1");

Hope that it helps.

Regards,

Franck Dauché


:

I am plugging away at autopopulating some fields of a repeating section
(including BriefDescription) given an item number, using the OnAfterChange
event for the item number. I started out using a secondary data source (a
view on SQL server) and couldn't get that to work, but got some help with
using ADO.net to access SQL server and get the data I need.

It works great for the first item in the section, but when a second item is
added, the fields in the first item are populated instead of in the second
item. That's exactly what I was telling it to do since I accessed the nodes
in this way:

Dim fDescNode As IXMLDOMNode =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:RequestedSample/my:BriefDescription")

So every time it is getting the first node in the repeated section. How do I
tell it to get the node which matches the ItemNumber that has just been
updated?

I hope this makes sense, because I'm learning XML as I go along!

Another question that just came up is: why doesn't my event handler happen
when I publish the form and fill it in from the published form? It works when
I'm previewing in InfoPath.

Thanks,
BethA
 
B

BethA

I was wrong - the published form doesn't autopopulate, even when published to
my hard drive! Any ideas? Maybe I'll post a new question just about that!

BethA

Franck Dauché said:
Hi Beth,

Why don't you loop through your nodes and put the values that you need:
IXMLDOMNodeList oNodeList =
thisXDocument.DOM.selectNodes("my:myFields/my:group1/my:group2");
if (oNodeList.length>0)
{
foreach (IXMLDOMNode oN in oNodeList)
{
if( oN.nodeType == DOMNodeType.NODE_ELEMENT )
{
IXMLDOMNode oField = oN.selectSingleNode("my:field1");
oField.text = "test"; //<-- Put your value here
}
}
}

Regards,

Franck Dauché


BethA said:
How do I tell what n is, given that I know which node triggered the event,
but not where it is in the group?

Thanks,
BethA

Franck Dauché said:
Hi Beth,

You can target the nth item in your section using code such as:
IXMLDOMNode oNode =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:group1/my:group2[n]/my:field1");

Hope that it helps.

Regards,

Franck Dauché


:

I am plugging away at autopopulating some fields of a repeating section
(including BriefDescription) given an item number, using the OnAfterChange
event for the item number. I started out using a secondary data source (a
view on SQL server) and couldn't get that to work, but got some help with
using ADO.net to access SQL server and get the data I need.

It works great for the first item in the section, but when a second item is
added, the fields in the first item are populated instead of in the second
item. That's exactly what I was telling it to do since I accessed the nodes
in this way:

Dim fDescNode As IXMLDOMNode =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:RequestedSample/my:BriefDescription")

So every time it is getting the first node in the repeated section. How do I
tell it to get the node which matches the ItemNumber that has just been
updated?

I hope this makes sense, because I'm learning XML as I go along!

Another question that just came up is: why doesn't my event handler happen
when I publish the form and fill it in from the published form? It works when
I'm previewing in InfoPath.

Thanks,
BethA
 

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