Selecting Value of Drop Down - InfoPath Dev
in

InfoPath Dev

Selecting Value of Drop Down

Last post 08-18-2006 08:45 AM by skrile. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 08-17-2006 05:59 AM

    • skrile
    • Top 500 Contributor
    • Joined on 08-17-2006
    • USA
    • Posts 29

    Selecting Value of Drop Down

    I've seen several iterations of this issue here, but can't seem to get any satisfaction in my form :).

    I am trying to set the value of a drop down. I can get it to work...sort of.

    At the top of my form, I have a NetworkID section that allows users to plug in their NetworkID. When they click a button, I use jscript in the OnClick event to perform a query on a secondary data source. If values are found corresponding to the network id, they are used to populate several text fields in the form below. Now, this is pretty straightforward - I set the default values of the text fields to the secondary data source.

    However, of course, drop downs don't have default values. So, when the button is clicked, the query is fired, and the fields update but the drop down doesn't. So, I set up a rule on the button that sets the value of the drop down equal to the corresponding value of the secondary data source.

    If I click the button twice, the drop down is reset as expected to the matching value. I'm guessing this is an order-of-operation thing. In other words, the rule is fired, then the OnClick event occurs. Is there any way to run the query first (oh and I need to pass parameters to the query, so making a rule to run the query won't work because you can't paramaterize within a rule)?
  • 08-17-2006 08:27 AM In reply to

    Re: Selecting Value of Drop Down

    Actually, you can set the default value for a dropdown that uses a lookup for its values but it's not obvious. What you have to do is set the default value in the node itself in the Data Source Pane. Go there and double-click the node to which your dropdown is bound. There you can type in the default value. You have to be careful that the value is in your set of allowed values.

    Second, correct rules execute first, then code. What you can do is set your query parameters via rules directly into the secondary data source query parameters nodes. Then execute the query using rules. This might help work around your issue.
    Shiraz Cupala / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 08-17-2006 08:37 AM In reply to

    • skrile
    • Top 500 Contributor
    • Joined on 08-17-2006
    • USA
    • Posts 29

    Re: Selecting Value of Drop Down

    Hmmm. Neither of these things seem to have helped. My drop-down is bound to a Secondary Data Source, so all of the nodes have a little lock icon on them and the default value section is grayed out.

    I guess I'm not following your second point. I have a SQL connection to an Employee table. I am using the OnClick event on my button to build a query statement based on values a user would put in to the form. I then execute the Query with values given by the user to return a row of information. That row contains a value that I want to set my drop down to. Does that make sense?
  • 08-17-2006 08:46 AM In reply to

    Re: Selecting Value of Drop Down

    Ah ok. I didn't realize your dropdown is bound to your secondary data source.

    It sounds like you need to move all this into code since you want to build the SQL query on the fly at a specific point. In code then you can manually set the value of the dropdown secondary DOM node as needed. Trying to mix in rules in this instance may be more trouble than it's worth given the order of event firing.
    Shiraz Cupala / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 08-17-2006 08:49 AM In reply to

    • skrile
    • Top 500 Contributor
    • Joined on 08-17-2006
    • USA
    • Posts 29

    Re: Selecting Value of Drop Down

    Right. So, what is the syntax to set the value of this. Here is the code I have so far:

    function CTRL270_5::OnClick(eventObj)
    {

    var thisUserName = XDocument.DOM.selectSingleNode("/my:myFields/my:InitiatorInformation/my:UserName").text;
    var thisUserDomain = XDocument.DOM.selectSingleNode("/my:myFields/my:InitiatorInformation/my:UserDomain").text;
    var thisNetworkID = thisUserDomain + "\\" + thisUserName;


    if(thisUserName=="")
    {
    XDocument.UI.Alert("You must enter your current Network User Name.");
    }
    else
    {
    // get the data adapter object
    myDataAdapter = XDocument.DataAdapters("viw_EmployeeSummary");

    // set the SQL command property of the data adapter, providing a dynamic WHERE clause
    myDataAdapter.Command = "select * from viw_EmployeeSummary WHERE NetworkID LIKE '" + thisNetworkID + "'";

    // execute the query
    myDataAdapter.Query();
    }
    }

    I'm guessing I'd set the value in the {else} portion of my logic. I just can't seem to find the right syntax to properly set the value of a drop down.
  • 08-18-2006 07:38 AM In reply to

    • skrile
    • Top 500 Contributor
    • Joined on 08-17-2006
    • USA
    • Posts 29

    Re: Selecting Value of Drop Down

    Well, it turns out just getting the value is a bit tricky in the onClick event. I've tried something like this:

    var facID = XDocument.GetDOM("FacilityCoordinators").SelectSingleNode("dfs:myFields/dfs:dataFields/d:Facility/FacilityID");

    But keep getting jscript errors ("Object does not support this property or method"). FacilityCoordinators is a secondary data connection that pulls data from a SQL query. Anyone out there see what I've got wrong here?
  • 08-18-2006 08:45 AM In reply to

    • skrile
    • Top 500 Contributor
    • Joined on 08-17-2006
    • USA
    • Posts 29

    Re: Selecting Value of Drop Down

    Oof. OK, I've managed to capture the data, but now I can't set the value of my dropdown. Here is how I got the data:

    var objEmployee = XDocument.GetDOM("viw_EmployeeSummary");
    objEmployee.setProperty("SelectionNamespaces",'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" ' + ' xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"');
    var objFound = objEmployee.selectSingleNode("//dfs:myFields/dfs:dataFields/d:viw_EmployeeSummary");
    var facID = objFound.selectSingleNode("@FacilityID").text;


    Phew. That gives me the facID (I only can get one record returned due to the nature of the query that populated "viw_EmployeeSummary"). So, now I want the value of a drop down to reflect the Facility Attribute (FacilityID) in the viw_EmployeeSummary results. And this officially does not work:

    XDocument.DOM.SelectSingleNode("/my:myFields/my:CoordinatorAssessment/my:CoordinatorContact/my:Facility") = facID

    I'm guessing this doesn't work because it is just dealing with the DOM and is not effecting the actual drop down control, but I actually have no idea....


    So, to abstract my question a little. How do you set the value of a drop down in an onClick event?
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.