Why doesn't this SetValue work? - InfoPath Dev
in

InfoPath Dev

Why doesn't this SetValue work?

Last post 06-17-2011 07:20 AM by JoanneWellings. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-15-2011 04:37 AM

    Why doesn't this SetValue work?

    Hi all -

    This should be a really simple bit of code, but I can't understand why it's not working.

    All I want to do is retrieve a value from one field and set another's fields value depending on the first.

    Here is the code:

     

    Public Sub Q_Select_1_Changed(ByVal sender As Object, ByVal e As XmlEventArgs)

    Set_Weighting("1")

    End Sub

    Public Sub Set_Weighting(QNo as String)

    ' Get question number and question

    Dim QuestionString As String = String.Concat("//my:myFields/my:Questions/my:Q_Select/my:Q_Select_", QNo)

    Dim WeightingString As String = String.Concat("//my:myFields/my:Questions/my:Q_Weighting/my:Q_Weighting_", QNo)

    Dim WeightingValue As Integer

    'Get value of Q_Select

    Dim nav As XPathNavigator = MainDataSource.CreateNavigator()

    Dim fieldValue As String = nav.SelectSingleNode(QuestionString, NamespaceManager).Value

    'Select case from string in Q_Select

    Select Case fieldValue

    Case "Yes"

    WeightingValue = 100

    Case "No"

    WeightingValue = 0

    Case "To be reviewed"

    WeightingValue = 25

    Case "Not required"

    WeightingValue = 100

    Case "In Progress"

    WeightingValue = 50

    Case "Awaiting Sign Off"

    WeightingValue = 75

    Case "Information not available"

    WeightingValue = 0

    Case "Immediate action required"

    WeightingValue = 0

    End Select

    'Set Q_Weighting value

    Dim nav2 As XPathNavigator = MainDataSource.CreateNavigator()

    nav2.SelectSingleNode(WeightingString, NamespaceManager).SetValue(WeightingValue)

    End Sub

    It just throws an InvalidOperationException error. When I hover over WeightingString, the xpath is as it should be. The WeightingValue is also correct. Can anyone see what the problem is? I have tried different permutations of the xpath, but nothing seems to work.

     TIA

  • 06-15-2011 06:10 AM In reply to

    Re: Why doesn't this SetValue work?

    Does the InvalidOperationException provide any other information?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-15-2011 06:19 AM In reply to

    Re: Why doesn't this SetValue work?

    Thanks for the reply

    The only other info I have is:

     System.InvalidOperationException
    Schema validation found non-data type errors.
       at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlDocument.ThrowExceptionFromMsxmlInteropError(MsxmlInteropError eError)
       at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlDocument.ThrowExceptionFromHresult(Int32 hrError)
       at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlNodeImpl.set_Text(String strText)
       at Microsoft.Office.InfoPath.MsxmlNavigator.SetValue(String value)
       at First_Aid_at_Work_Assessment___Draft_v0._1.FormCode.Set_Weighting(String QNo)
       at First_Aid_at_Work_Assessment___Draft_v0._1.FormCode.Q_Select_1_Changed(Object sender, XmlEventArgs e)
       at Microsoft.Office.InfoPath.Internal.XmlEventHost.GenericProxy(Object genericDelegate, DataDOMEvent dataDOMEvent, InfoPathEvents type)
       at Microsoft.Office.InfoPath.Internal.XmlEventHost.ChangedProxy(DataDOMEvent dataDOMEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOMEventSink_SinkHelper.OnAfterChange(DataDOMEvent pDataDOMEvent)

    It seems to be to do with trying to pass an integer, so I changed them all to strings just to see if it would stop the error. The same error occurred.

     

     

  • 06-15-2011 07:51 AM In reply to

    Re: Why doesn't this SetValue work?

    Most likely, the node has an xsi:nil attribute that needs to be removed before you can set a value to it.  Search this forum for xsi:nil, and you should find plenty of help.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-17-2011 07:20 AM In reply to

    Re: Why doesn't this SetValue work?

    Thank you! So simple too. I gave the Q_Weighting fields a default value of 0 and now it works correctly. Hope this helps someone else!
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.