Solved

Infopath Custom Code Issue

Posted on 2013-10-29
7
358 Views
Last Modified: 2013-11-04
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

0
Comment
Question by:redeux-tech
  • 5
  • 2
7 Comments
 
LVL 28

Expert Comment

by:clayfox
ID: 39609404
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
 
LVL 1

Author Comment

by:redeux-tech
ID: 39609569
I already tried removing the check box and it is still not working.
0
 
LVL 28

Expert Comment

by:clayfox
ID: 39609577
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:redeux-tech
ID: 39609582
This what the error looks like in progress....
0
 
LVL 1

Author Comment

by:redeux-tech
ID: 39609686
I have the datasource for this field set to position().  Is that what is causing this to not return a value?
0
 
LVL 1

Accepted Solution

by:
redeux-tech earned 0 total points
ID: 39612074
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
 
LVL 1

Author Closing Comment

by:redeux-tech
ID: 39621080
I solved my own issue and I outlined the solution in this comment.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question