Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a repeating table in a List view where each row has a button that when clicked should switch to an Edit view while loading the selected row details. Based on a lot of research and postings I see that there are two ways to accomplish this. One is to put a action rule on the button and the other is custom code tied to the Click event of the button.

My problem is that neither of these solutions seems to work..and for slightly different reasons. The underlying issue is that I cannot seem to extract the field that holds the row id so I can then pass it on the the new view.

The data coming in is via a web service and has the following XPath (not sure if that is the correct terminology) --

myField / dataFields / tns:GetItemsResponse / GetItemsResult / q1:Item / ReferenceId
myField / dataFields / tns:GetItemsResponse / GetItemsResult / q1:Item / field2
myField / dataFields / tns:GetItemsResponse / GetItemsResult / q1:Item / field3
myField / dataFields / tns:GetItemsResponse / GetItemsResult / q1:Item / ...

Action Rule

The rule tries to set a queryField field on a Secondary connection using the following expression

current()/ReferenceId

However, when I run it I get the following very unhelpful error message

Some rules were not applied.
Unspecified error

If I set the expression to just

current()

I get back all the values from all the fields as a single concatenated value. This seems to indicate that current() does have the correct row referenced but I just cannot seem to get a specific field.

Code

Meanwhile, the following code pops up an Object reference not set set to an instance of an object exception

Public Sub EditItemButton_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
   Dim sourceNav As XPathNavigator = e.Source.CreateNavigator()

   MessageBox.Show(sourceNav.InnerXml)

   Dim idNav As XPathNavigator = sourceNav.SelectSingleNode("ReferenceId", Me.NamespaceManager)

   MessageBox.Show(idNav.InnerXml)
End Sub

The first MessageBox call (for sourceNav) shows the XML for the currently selected row. And I see the ReferenceId node in there. But again, I cannot seem to get access to it via the SelectSingleNode.

I have tried all different combinations of ReferenceId including "../ReferenceId", "q1:ReferenceId" (that is what shows in the designer and when I copy the XPath), "a:ReferenceId" (the "a:" is what shows when the sourceNav.InnerXml is displayed..but I do not understand why...)

Any thoughts or ideas?

Thanks.

share|improve this question
    
you got any solution for above stated issue? i am having similar issue in my Form. however, i have to use current row filed selected value as filter for another control in the same row. plz let me know if you nailed it. thanks raj –  user703326 Aug 1 '12 at 17:42
add comment

1 Answer 1

up vote 0 down vote accepted

I do not recall the exact circumstances to solving this issue but the following code ended up working. If I remember correctly the key to the solution was the "local-name" but I could not explain it. One thing I never did come to grips on with InfoPath was all the different XML naming conventions...there just did not seem to be any rhyme or reason to why something was named the way it was.

Public Sub EditButton_Clicked(ByVal sender as Object, ByVal e as ClickedEventArgs)
   ' get selected reference id
   sourceNav As XPathNavigator = e.Source.CreateNavigator()
   idNav As XPathNavigation = sourceNav.SelectSingleNode("*[local-name()='ReferenceId'")

   ' set it for Edit view and fetch data
   Dim wsNav As XPathNavigator = Me.MainDatasource.CreateNavigator()

   Dim referenceIdNav As XPathNavigator = wsNav.SelectSingleNode("/dfs:myFields/dfs:queryFields/tns:GetRecord/tns:id", Me.NamespaceManager)
   DeleteNil(referenceIdNav)
   referenceIdNav.SetValue(idNav.Value)

   Me.MainDataSource.QueryConnection.Execute()

   ' show the view
   Me.ViewInfos.SwitchView("Edit")
End Sub

Protected Sub DeleteNil(ByVal node as XPathNavigator)
   If (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance")) Then
          node.DeleteSelf()
   End If
End Sub

Hope this helps.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.