Tuesday 26 May 2009

Populate InfoPath text box based on dropdown list box selection

Following steps will illustrate how to populate InfoPath form text box based on drop down list box selection.


Scenario is, when retrieving data from SharePoint list, we may need more fields to be appear in our InfoPath form based on our selection. The following example will show, how to retrieve items description based on item code selection in SharePoint list.

Steps


Create a data source to retrieve data from SharePoint lits in InfoPath
Add repeating table as follows (You can add any data control from InfoPath controlls)
Change text box to drop down list box in item code column in the repeating table

Double click the drop down list box and select the data source connection you created for the SharePoint list to retreive data from



Click the RULES button to create a rule for this drop down list box

Add rule - add condition - action (select the field's value as) - field (select the field you want have the display. In this case its item description text box)

Click on Fx button to insert formula - click insert field group - select data source (secondary) - select description field - click on filter data button - click add - select ID from secondary data source is equals to Description from the secondary data source


Click on OK button untill you return to following screen



Click on EditXPath (advanced) check box and change the code as follows


xdXdocument:GetDOM("Inventory Item")/dfs:myFields/dfs:dataFields/dfs:Iventory_Item/@Description[../@ID = current()]





Finally when you see the preview of created InfoPath form, you should be able to retrieve Item description by selecting Item code in drop down list box.











20 comments:

  1. You are very kind to share your expertise. I live in Indianapolis, Indiana, United States of America. I am a beginner in Infopath development. Thank you for these instructions.

    ReplyDelete
  2. Indianapolis is a very boring town.

    ReplyDelete
  3. As boring as your boring comment?

    ReplyDelete
  4. Thank you, :)

    ReplyDelete
  5. Thanks a lot!
    Your post saved us a lot of time.
    It was very descriptive!

    ReplyDelete
  6. Thanks so much for this post! Helped me tremendously! KD - San Francisco, CA USA

    ReplyDelete
  7. nice tutorial!! but how do you clear the textbox when you select a different item from the dropdownlist?

    ReplyDelete
  8. Hello SharePoint Shrilanka,
    Thank you so much for your post. I'd appreciate about that.

    @By the way, I found one post mentioning about clearing the field named MyField with VB:

    Dim root As XPathNavigator = MainDataSource.CreateNavigator()
    Dim textbox As XPathNavigator = root.SelectSingleNode("/my:myFields/my:MyField", NamespaceManager)

    MyField.SetValue("")

    ReplyDelete
  9. Very nice - thanks for sharing!!

    ReplyDelete
  10. HI,
    I have similar requirement.but in my case I have a dropdown list which has sharepoint list as a datasource and there is a button to insert the dropdown list selected value into the repeating table(we can insert multiple dropdown list values in repeating section).
    Now I replaced one of list item values from xxx to yyy in datasource(sharepoint list). the updated list item are coming the infopath dropdown list. But the old listitem value(xxx) what I have inserted earlier in the repeating section is not getting changed. can you help me in this?

    Note: I have removed the dataconnection and added it again to refresh.

    Also I am using same dataconnection variable in repeating section what i am using to the dropdown list values.

    ReplyDelete
  11. saved me alot of time. nice and clear

    ReplyDelete
  12. I have been working this for a week and I cannot get this to work. I made a simple infopath sheet and a SP list. I need the drop down box to have all the ID #s for the SP list to show (which they do) Once I pick one from the list I need it to pull from the SP list and put it in an infopath text box. It should be easy, I have found plenty of directions on it, but the closest I have come to getting this is that it will display the first last name in the SP list but when I change the drop down it will not update. Also I tried your method and when I get to the filter, I get an error that the dropdown box is not allowed to have a filter on it. Please help me before I rip my hair out! :)

    ReplyDelete
  13. Yor are my Hero....

    ReplyDelete
  14. i had to change the place where you say ID to use the actual title field of the sharepoint list column - using ID would not work for me

    ReplyDelete
  15. Hello dir.


    this tutorial has very very help me and best technique
    regarding xdXdocument:GetDOM("Inventory Item")/dfs:myFields/dfs:dataFields/dfs:Iventory_Item/@Description[../@ID = current()]

    thanks

    ReplyDelete
  16. Thank you. Your help is appreciated.

    ReplyDelete
  17. Thanks! This is a related post on how to get filtered values from SharePoint list column in InfoPath text field -
    http://www.sharepointbreak.com/2012/12/06/get-filtered-values-from-sharepoint-list-column-in-infopath-text-field/

    ReplyDelete
  18. Hi

    I have a similar scenario but I'm facing error in the XML saying :

    'Current' is not a valid XSLT or XPath function.

    xdXDocument:GetDOM("Value Stream1")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Project_x0020_Manager[../d:ID = -->Current()<--]


    I have a TEAM dropdown menu from SP list and the Project manager should be filled based on the team.

    In the Team SP List I have Team names and respective Project manager.

    Using Infopath 2010. Any help would be great.

    ReplyDelete
  19. I have InfoPath 2013. a list in SP2013 with over 800 entries and several columns containing data. if my user picks e.g company ID I would like company name, address, zip, town etc to be filled in automatically in my text boxes. how?

    ReplyDelete
  20. You're my hero! Thanks!

    ReplyDelete