Populate data on the form when it opens - InfoPath Dev
in

InfoPath Dev

Populate data on the form when it opens

Last post 05-09-2005 11:22 PM by Jason. 19 replies.
Page 1 of 2 (20 items) 1 2 Next >
Sort Posts: Previous Next
  • 04-30-2005 04:36 AM

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Populate data on the form when it opens

    Hi

    I wanted to populate the data into the fields on the form when the form is open.

    I can able populate the with button click event, but if I uses the same code in _startup method I am getting error.


    This is really urgent anybody knows the solution please let me know ASAP.

    Thanks
    Jason
  • 04-30-2005 06:50 AM In reply to

    Re: Populate data on the form when it opens

    Hi Jason,
    Welcome to the board.
    Write your code in the onload method.
    Here is the the method where you need to write your code in

    [InfoPathEventHandler(EventType=InfoPathEventType.OnLoad)]
    public void OnLoad(DocReturnEvent e)
    {
    //Write your code here
    }

    This is the method that executes when the form is loaded.
    Note:Above method is in c#

    Agni
    InfoPathDev India
  • 04-30-2005 10:21 PM In reply to

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Re: Populate data on the form when it opens

    Thank you very much Agni.
  • 05-01-2005 05:56 AM In reply to

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Re: Populate data on the form when it opens

    Hi Agni:

    Following code is populating data in table with buttonClick event, but it is giving error
    in OnLoad event. Could you please let me know what changes do I need to make work this code in OnLoad.

    ____________



    Dim oDataSet As New DataSet
    Dim lstrQueryXml As String
    lstrQueryXml = "<test><contact>"
    lstrQueryXml &= "<contactid>ContactId1</contactid>"
    lstrQueryXml &= "<firstname>FirstName1</firstname>"
    lstrQueryXml &= "<lastname>LastName1</lastname>"
    lstrQueryXml &= "<ssn>123456789</ssn>"
    lstrQueryXml &= "<crm>CRM1</crm>"
    lstrQueryXml &= "</contact>"
    lstrQueryXml &= "<contact>"
    lstrQueryXml &= "<contactid>ContactId2</contactid>"
    lstrQueryXml &= "<firstname>FirstName2</firstname>"
    lstrQueryXml &= "<lastname>LastName2</lastname>"
    lstrQueryXml &= "<ssn>123456782</ssn>"
    lstrQueryXml &= "<crm>CRM2</crm>"
    lstrQueryXml &= "</contact>"
    lstrQueryXml &= "<contact>"
    lstrQueryXml &= "<contactid>ContactId3</contactid>"
    lstrQueryXml &= "<firstname>FirstName3</firstname>"
    lstrQueryXml &= "<lastname>LastName3</lastname>"
    lstrQueryXml &= "<ssn>123456783</ssn>"
    lstrQueryXml &= "<crm>CRM3</crm>"
    lstrQueryXml &= "</contact></test>"

    Dim lXmlDocContacts As New XmlDocument
    lXmlDocContacts.LoadXml(lstrQueryXml)
    Dim root As XmlElement
    root = lXmlDocContacts.DocumentElement
    Dim directoryList As XmlNodeList
    directoryList = root.SelectNodes("/test/contact")
    Dim i As Integer
    For i = 0 To directoryList.Count - 1
    If i <> 0 Then
    thisXDocument.View.ExecuteAction("xCollection::insert", "ContactDetails_1")
    End If
    With thisXDocument.DOM
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:CIFNumber").text = directoryList(i).Item("contactid").InnerText
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:FirstName").text = directoryList(i).Item("firstname").InnerText
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:LastName").text = directoryList(i).Item("lastname").InnerText
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:SSN").text = directoryList(i).Item("ssn").InnerText
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:CRM").text = directoryList(i).Item("crm").InnerText
    End With
    Next


    -------------------

    Thanks
    Jason

  • 05-01-2005 09:08 PM In reply to

    Re: Populate data on the form when it opens

    I am not sure why you are getting error.
    Can you debug your code and check out on which line you are getting the error and copy paste the error message here please.

    Agni
    InfoPathDev India
  • 05-02-2005 04:44 AM In reply to

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Re: Populate data on the form when it opens

    Hi Agni:

    I am getting error message second time when it tries to fill the table:



    System.NullReferenceException
    Object reference not set to an instance of an object.
    at MySecondInfoPathApp.MySecondInfoPathApp.OnLoad(DocReturnEvent e) in C:\Inetpub\wwwroot\MySecondInfoPathApp\FormCode.vb:line 88
    at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)

    -------------

    at:


    If i <> 0 Then
    thisXDocument.View.ExecuteAction("xCollection::insert", "ContactDetails_1")
    End If
    With thisXDocument.DOM
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:CIFNumber").text = directoryList(i).Item("contactid").InnerText
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:FirstName").text = directoryList(i).Item("firstname").InnerText
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:LastName").text = directoryList(i).Item("lastname").InnerText
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:SSN").text = directoryList(i).Item("ssn").InnerText
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:CRM").text = directoryList(i).Item("crm").InnerText
    End With
    -------------------


    Thanks
    Jason



  • 05-02-2005 08:53 AM In reply to

    Re: Populate data on the form when it opens

    Hi Jason,
    According to my guess "thisXDocument.View.ExecuteAction("xCollection::insert", "ContactDetails_1")" statement is not working, because in onload method "View" object is not created and you are trying to Insert a row with the help of "View" object. You can find this by taking you mouse hover the "View" in the above statement.

    You can referhttp://www.infopathdev.com/forums/topic.asp?TOPIC_ID=303 to learn about how to insert a row in the code.




    Agni
    InfoPathDev India
  • 05-05-2005 07:13 PM In reply to

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Re: Populate data on the form when it opens

    Hello Agni:

    I am still getting error to populate the repeating table.Cloud you please send the more specific code sample to my problem.

    Thanks
    Jason
  • 05-08-2005 03:36 AM In reply to

    Re: Populate data on the form when it opens

    Here is more specific code to insert a row,
    //get "my:myFields" node to insert "my:ContactDetails" details node.
    oParentNode = thisXDocument.DOM.selectSingleNode("/my:myFields");

    //Create a string with the xml that you want to insert
    string xmlString = "<my:ContactDetails><my:CIFNumber/><my:FirstName/><my:LastName/><my:LastName/><my:SSN/><my:CRM/><my:ContactDetails/>";

    //create a new xml document
    IXMLDOMDocument domXMLNode = (IXMLDOMDocument)thisXDocument.CreateDOM();
    //Load that xml into above dom
    domXMLNode.async = false;
    domXMLNode.loadXML(xmlString);

    //Append your new node to the parentnode.
    oParentNode.appendChild(domXMLNode.documentElement);

    after this you can write your code to insert data into the new row.

    Agni
    InfoPathDev India
  • 05-08-2005 05:29 PM In reply to

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Re: Populate data on the form when it opens

    Hi Agni:

    I am doing small mistake.
    I got the following error message:

    System.ArgumentException
    Reference to undeclared namespace prefix: 'my'.

    at Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode.appendChild(IXMLDOMNode newChild)
    at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper.appendChild(IXMLDOMNode newChild)
    at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper.appendChild(IXMLDOMNode newChild)
    at MySecondInfoPathApp.MySecondInfoPathApp.OnLoad(DocReturnEvent e) in C:\Inetpub\wwwroot\MySecondInfoPathApp\FormCode.vb:line 97
    at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)


    ___________________
    For this code:

    Dim lXmlDocContacts As New XmlDocument
    lXmlDocContacts.LoadXml(lstrQueryXml)
    Dim root As XmlElement
    root = lXmlDocContacts.DocumentElement
    Dim directoryList As XmlNodeList
    directoryList = root.SelectNodes("/test/contact")

    Dim oParentNode As IXMLDOMNode
    oParentNode = thisXDocument.DOM.selectSingleNode("/my:myFields")
    Dim strFields As String
    strFields = "<my:ContactDetails><my:CIFNumber/><my:FirstName/><my:LastName/><my:SSN/><my:CRM/><my:ContactDetails/>"
    Dim domXMLNode As IXMLDOMDocument
    domXMLNode = thisXDocument.CreateDOM()

    domXMLNode.async = False
    domXMLNode.loadXML(strFields)

    oParentNode.appendChild(domXMLNode.documentElement)
    ------------

    Thanks
    Jason
  • 05-08-2005 09:12 PM In reply to

    Re: Populate data on the form when it opens

    Sorry Jason it was my mistake,
    there should be reference to the "my" namespace in the "xml string". For that please open your xml schema and check for "my" namespace and add it to the string
    for example:-
    strFields = "<my:ContactDetails xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-04-29T04:21:12\"><my:CIFNumber/><my:FirstName/><my:LastName/><my:SSN/><my:CRM/><my:ContactDetails/>"

    Note: Donot copy paste my xml string, look at "schema.xsd" and take "my" namespace from there.


    Agni
    InfoPathDev India
  • 05-08-2005 10:36 PM In reply to

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Re: Populate data on the form when it opens

    Hi Agni:

    Could you please check the syntax for the string.

    Thanks for your time.
    Jason
  • 05-09-2005 11:24 AM In reply to

    Re: Populate data on the form when it opens

    sorry it should have been
    strFields = "<my:ContactDetails xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-04-29T04:21:12\"><my:CIFNumber/><my:FirstName/><my:LastName/><my:SSN/><my:CRM/></my:ContactDetails>"


    Agni
    InfoPathDev India
  • 05-09-2005 01:03 PM In reply to

    • Jason
    • Not Ranked
    • Joined on 04-23-2005
    • Posts 11

    Re: Populate data on the form when it opens

    Hi Agni:

    Thank you very much. I got it now.

    Could you plese tell how to insert the data now?

    Thanks again
    Jason
  • 05-09-2005 07:12 PM In reply to

    Re: Populate data on the form when it opens

    Hey now our previous code should work
    With thisXDocument.DOM
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:CIFNumber").text = "CIFNumber"
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:FirstName").text = "FirstName"
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:LastName").text = "LastName"
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:SSN").text ="SSN"
    .selectSingleNode("/my:myFields/my:ContactDetails[" & i + 1 & "]/my:CRM").text = "CRM"
    End With

    Agni
    InfoPathDev India
Page 1 of 2 (20 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.