none
Get the Display Name of a dropdown into a text box RRS feed

  • Question

  • I have created a dropdown control and a text box control in my infopath form. I am binding some values to the dropdown control from a sql database with "value" field as "@ID" and "Display name" as "@Name"

    Now, when the user select the dropdown the display name should be auto-populated in the textbox I created, not the "@ID" value.

    How to achieve this.

    Tuesday, August 24, 2010 7:32 AM

Answers

  • What you need to do is add a rule to your dropdown that set's the value of the text box to the @Name node of the secondary data source and filter it where @ID is equal to the dropdown on the form.

    • Dropdown > Add Rule
    • Set a Field's Value
    • Field = textbox
    • Value = @Name[@ID=Dropdown] (use a filter on the @Name node)

    SharePoint Architect || Microsoft MVP || My Blog
    Planet Technologies || SharePoint Task Force
    • Marked as answer by EstoySol Thursday, August 26, 2010 7:13 AM
    Wednesday, August 25, 2010 3:24 AM

All replies

  • What you need to do is add a rule to your dropdown that set's the value of the text box to the @Name node of the secondary data source and filter it where @ID is equal to the dropdown on the form.

    • Dropdown > Add Rule
    • Set a Field's Value
    • Field = textbox
    • Value = @Name[@ID=Dropdown] (use a filter on the @Name node)

    SharePoint Architect || Microsoft MVP || My Blog
    Planet Technologies || SharePoint Task Force
    • Marked as answer by EstoySol Thursday, August 26, 2010 7:13 AM
    Wednesday, August 25, 2010 3:24 AM
  • Could you please repeat your fix for this issue in newb terms? I have an InfoPath 2007 form I created and published to a SharePoint 2007 site. It contains three fields that I promoted from the form. They are 'A', 'C', and 'I'. Each are build as cascading drop downs and each are a SharePoint list to provide the Secondary Data. When I make my selections from the dropdowns, I see the correct 'text' or 'named' values. However when I then refresh the SharePoint list, each of the columns shows the ID instead of the name/value. I understand your first three steps in the previous post. The last step: Value = @Name[@ID=Dropdown] (use a filter on the @Name node)

    I just don't understand by what you mean (use a filter on the @Name node)

    Thursday, May 5, 2011 9:50 PM
  • Can you please explain Clayton Cobb

     @Name[@ID=Dropdown] (use a filter on the @Name node)

    I have dropdown canidate name and ID

    I have textbox called Title

    I tried Candidate name[ID=Candidate name] and it won't let me do that?

    I can get it to put the name in the box but it is always the first item in the dropdown list I can't get it to pick the correct item?

    Thanks

    Monday, October 8, 2012 1:27 PM
  • This might get a bit confusing without snapshots but I will give it a try. Although there is logic to how infopath arrives at it, it can be quite confusing when you are new to infopath.

    Click Manage Data connections and make sure the value you want to retrieve is checked off in the data connection profile. (example: Data Connection is Employees, make sure Name is checked so you can retrieve it later.)

    Create a text field

    On dropdown field of lookup, click and choose Add Rule from top menu (This field changes)

    Set a fields value.

    Value function (fx) à Insert field or group à Show advanced view à choose secondary data source from top fields dropdown that contains your value that you want to populate the textbox with.

    Expand  +myFields

    Expand +dataFields

    Expand +d:SharePointListItem_RW

    ( This part is the mindbender in following the logic, but there is logic to it )

    Left click value you want in the textbox.

    Click Filter Data à Add à put the id value in the first dropdown box , “is equal to” in the second.

    Now, In the third dropdown click “Select field or group”.

    Go to the Fields dropdown at the top and choose “Main”

    Expand folders and choose the field that contains your lookup.

    Basically, all of this says find the value you want to use (as in Name) where the ID equals the ID of the Dropdown box value.

    • Proposed as answer by Stoneman3735 Thursday, October 11, 2012 12:54 PM
    Wednesday, October 10, 2012 8:33 PM
  • Thank YOU!!!! so so much!

    That works!  :)

    This was the key!

    Left click value you want in the textbox. then continue on

    I kept double clicking the field and putting it into the formula and you do not need to just highlight it and when you click ok "IT" will put it in the formula!

    Thursday, October 11, 2012 12:53 PM
  • Awesome post! I spent 4 hours today trying to accomplish this and was only successful after finding your reply. Thank you for your valuable contribution!
    Wednesday, November 28, 2012 1:52 AM
  • I just wanted to add this in case it is helpful for someone else.

    I got this directly from this blog posting, but tried to more cleanly document the steps for InfoPath 2010

    ================
    (I adapted it to use some fields from a view on our SQL Server)



    This presumes that I have created a 'data connection' called " vw_Test1" (created from an SQL view), and that it has the fields:
        PK {using as drop-down value, e.g. the Primary Key}
        Name {using as drop-down Display Name} {or even a another column from the view such as: eMail}

        
    Data {tab} => Data Connections =>
        Make sure the data connection to the view  is selected (vw_Test1)
        
        If the connection is already there, you can click [Modify] to see the fields; make sure that the 'name' field,
            i.e. the field that is the 'display name' for the drop-down is checked
            
    In the Fields Pane, on right side of window, create a field for the drop-down display name, "Test1_DisplayName"
        Note that field that is bound to the value of the drop down is also there, "Test1_ValueField"


    Home {tab} => Rules {Section} => Manage Rules {icon} => {opens up the Rules pane
        With the Rules pane open, select the drop-down control.
        Click 'New' in the Rules pane => Action
            Name the Rule: DropDown_PopulateDisplayNameField
        Click Run these Actions => [Add]:
        (
        Set a fields value
        Field:
        select: "Test1_DisplayName"
        Value:
            Click [fx] => Insert Formula {window}
                [Insert Field or Group...]
                    In the upper drop-down select the secondary data source: "vw_Test1"
            expand the tree to show the field: ":Name"

                    [Filter Data] => Filter Data {Window}
                        [Add] => Specify Filter Conditions {Window}
                        (
                            Put "PK" in left box   {from the view}
                            Then "Is Equal to"
                            Right Box: “Select field or group”
                            Go to "Main" data source
                            Select the field in the form: "Test1_ValueField"
                        [OK]
                        )
                        [ok]
                        [ok]
             [OK]                                                
            Now see formula:
            @Name[@PK=Test1_ValueField]
            {or for email, i.e. some other field in the view:   
                        @eMail[@DB2_T9_FK_employee = DB2_T9_FK_employee]  
            }
            [OK]
            Now in the rule details {window} see that same formula in the "Value:" field
            
        )



    Friday, April 12, 2013 6:38 PM
  • Thank you very much for this explanation. It was extremely clear. I had been trying to do this for quite some time. Thanks!!
    Wednesday, August 21, 2013 7:04 PM
  • I just logged in to vote up this answer. This is the answer that solved it for me.

    Thank you.

    Tuesday, July 16, 2019 11:48 AM