last modified date on repeating section

B

billsmailbox

I am fairly new to InfoPath and am working on a PRB type form. What I
have is a repeating section with the following fields: Issue,
Resolution, Last Modified date and author. The reason I use a
repeating section is so that all issues related to a specific
application can be in the same form.

When the author creates a new section in the repeating section the date
is automatically populated with the current date and the author is
populated with the current user via System.Environment.UserName. This
part works. However, what I want to do is if someone else modifies
this section (e.g. updated information), I want to change the modified
date with the current day and the author name with the current user
assuming it's a different person for that section only. What I've done
so far changes it for the field in all the sections of the repeating
section.

Has someone tried to do this before or have come across this?
 
F

Franck Dauché

Hi Bill,

It is because you need to target the nth instance of your repeating section.
In the OnAfterChange event of one of your field, use code such as:
IXMLDOMNode oNode = e.Site.selectSingleNode("..");
IXMLDOMNode oField1 = oNode.selectSingleNode("my:field1");
oField1.text = "test";
This code will change the value of field1 in the row when the event was
triggered.

If you do it with a button in that row, you would use e.Source instead of
e.Site

Hope that it helps.

Regards,

Franck Dauché
 
B

billsmailbox

Thanks for the quick reply. Here's my modified code:

Dim oNode As IXMLDOMNode
Dim nodePRBAuthor As IXMLDOMNode
oNode = e.Site.selectSingleNode("..")
nodePRBAuthor =
oNode.selectSingleNode("my:myFields/my:pRBSection/my:pRB_Repeating_Section/my:pRBAuthor")
nodePRBAuthor.text = System.Environment.UserName

but now I get the following error message:
"System.NullReferenceException
Object reference not set to an instance of an object."
 
B

billsmailbox

I think I found the problem... I changed my code to the following and
it works fine:

Dim nodePRBAuthor As IXMLDOMNode
nodePRBAuthor = e.Site.selectSingleNode("../my:pRBAuthor")
nodePRBAuthor.text = System.Environment.UserName

Thanks a lot Franck!
 
F

Franck Dauché

Hi,

You can't use the full XPath:
nodePRBAuthor =
oNode.selectSingleNode("my:myFields/my:pRBSection/my:pRB_Repeating_Section/my:pRBAuthor")

Instead, use something such as:
nodePRBAuthor =
oNode.selectSingleNode("my:pRBAuthor")

This assumes that the event was triggered by a node at the same level as
PRBAuthor
In the code snippet I posted, e.Site.selectSingleNode("..") is bringing you
down to my:myFields/my:pRBSection/my:pRB_Repeating_Section

Hope that it helps.

Franck Dauché
 

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