Infopath Custom Code Issue

I am using a loop to iterate through my Main Nodes in a repeating table in Infopath 2010.
When I get to the field that I am using a calculated value as the default I am getting an error, "Object reference not set to an object",

Here is my code:

 'Count the amount of Field nodes
            Dim iter As XPathNodeIterator = root.Select("/my:myFields/my:ImportFields/my:Fields", NamespaceManager)
            Dim FieldsCount As Integer = iter.Count
            Dim sb As New System.Text.StringBuilder()

            If FieldsCount > 0 Then
                'Check mappings.
                While iter.MoveNext
                    If iter.Current.SelectSingleNode("my:FieldName", NamespaceManager).Value = "" Or iter.Current.SelectSingleNode("my:MappedField", NamespaceManager).Value = "None" Then
                        sb.Append("Row " & iter.Current.SelectSingleNode("my:RowNo", NamespaceManager).Value & " is not mapped." & System.Environment.NewLine)
                    End If
                End While

Open in new window

LVL 1
redeux-techAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
redeux-techConnect With a Mentor Author Commented:
Ok, I figured out my own problem here.  

1 -  I had to fix the field so that it's datasource was no longer position()

2-  I had to map the calculated value field so that it was mapped to the field on the Main datasource so that the value was saved.

3 -  I set the field's default value to count(preceding-sibling::*/RowNo) + 1 and it doesn't matter that refresh value when formula is calculated is checked.

4 - I had to make sure that my code that inserted new rows into the repeating table (XMLWriter) was inserting the nodes in the correct order as they appeared in the Main datasource.
0
 
Clay FoxDirector of Business IntegrationCommented:
You may have the recalculate check box on the default value. It may be looping trying to recalculate when you move through the field.
0
 
redeux-techAuthor Commented:
I already tried removing the check box and it is still not working.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Clay FoxDirector of Business IntegrationCommented:
Maybe try removing the default value and just use a rule or code at load that sets the value.

Might allow you to get around the issue.
0
 
redeux-techAuthor Commented:
This what the error looks like in progress....
0
 
redeux-techAuthor Commented:
I have the datasource for this field set to position().  Is that what is causing this to not return a value?
0
 
redeux-techAuthor Commented:
I solved my own issue and I outlined the solution in this comment.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.