How to force click "Check names" in a contact selector control - InfoPath Dev
in

InfoPath Dev

How to force click "Check names" in a contact selector control

Last post 09-11-2008 08:12 AM by nailbiter. 16 replies.
Page 1 of 2 (17 items) 1 2 Next >
Sort Posts: Previous Next
  • 06-20-2008 05:41 AM

    • Bleak
    • Top 500 Contributor
      Male
    • Joined on 04-16-2008
    • Germany
    • Posts 28

    How to force click "Check names" in a contact selector control

    I have a contact selector control I use to get a userID, which I then feed to a web service to get some account data from the AD. This works well in InfoPath, but seems to have a strange bug when opened in a browser:

    The AccountId property of a contact selector is part of a repeating section. When I try to read it, Infopath simply takes the first element, which is what I want. In a browser, however, the picked up ID seems to be the one immediately before the changed one (meaning that it returns null when you enter first value foo, then returns foo after you enter bar, etc). Clicking on the "Check names" control button updates the necessary fields, so I'm looking for a way to (programmatically?) ensure this happens every time before data is sent to the web service.

     

    Another solution to this would be a browser-compatible way to read from the first row of a repeating section. Does anyone know of such a way?

     

  • 08-07-2008 12:46 PM In reply to

    Re: How to force click "Check names" in a contact selector control

    Did you find a solution?  I posted the same problem in the MSDN SP/InfoPath Forum:

    http://forums.msdn.microsoft.com/en-US/sharepointinfopath/thread/907c8744-e15e-48c8-99de-27de18b64d5c

    There must be a very simple way to resolve this.

  • 08-07-2008 02:46 PM In reply to

    • Bleak
    • Top 500 Contributor
      Male
    • Joined on 04-16-2008
    • Germany
    • Posts 28

    Re: How to force click "Check names" in a contact selector control

     The simplest solution would be to use position(0) or first() directly in the rules section, but, these functions are forbidden for some reason. So I resorted to addressing the first element of the list in the code via an xml statement. ( ...[1] )

  • 08-07-2008 05:24 PM In reply to

    Re: How to force click "Check names" in a contact selector control

    Thanks for the suggestion.  Did you have to add a button and buttonclick logic to do so?  Would you mind sharing your code?  Appreciate it.

  • 08-07-2008 05:39 PM In reply to

    • Bleak
    • Top 500 Contributor
      Male
    • Joined on 04-16-2008
    • Germany
    • Posts 28

    Re: How to force click "Check names" in a contact selector control

     No, I was unable to interact directly with the picker. All I could do was manipulate the data structure it provides to make sure that the first element is always selected.

    I do not have the code on hand right now (and won't until Monday), but the idea itself is pretty simple - you address the DOM node like an array (i.e: nodeset/Person[1]/AccountId) and store this value wherever you need that first element. This can only be done via code, AFAIK (just a simple SetValue assignment).

     It'd be great if someone found out how to click the damn button automatically, though.

  • 08-11-2008 04:15 AM In reply to

    • altja
    • Not Ranked
      Male
    • Joined on 07-02-2008
    • Grand Rapids, MI
    • Posts 10

    Re: How to force click "Check names" in a contact selector control

    XPathNavigator nodeId = mMainDataSource.SelectSingleNode("//my:path/my:Person/my:AccountId[1]", NamespaceManager);

    if (nodeId != null)  //Do something

     

    I also, just take the first one and have not found a way to click the button automatically per say.

     

  • 08-12-2008 10:17 AM In reply to

    Re: How to force click "Check names" in a contact selector control

    I am at a loss.  Is it really just my xpaths that are faulty or is it also the type of event handler I am declaring/working on?  Well, all that and faulty coding?  Let me ask, will a changed event trigger each time a new row is added to a repeating table?  Or do I need a different handler?  Morever, is the handler associated with the right grouping?  Please note that I am using the default insert row functionality that comes with the repeating table control (in other words, I am not using a button control).  That said, assuming that a changed event triggers with each new row insert, then the problem is definitely with the xpaths and/or the code.  Currently, I can auto-populate the person's job title textbox ***for the first row only***.  Once I insert another row and resolve a name from the Contact Selector, however, the person's job title textbox no longer auto-populates and so on with other inserted rows.

    This is happening in a ***browser-enabled*** form in the browser (not in preview mode). 

    Can someone please let me know how to resolve this quickly?

    My main data source for this particular set of fields looks like:

    (...)
    selector_table (repeating group)
        selector_control
           Person (repeating group)
              DisplayName
              AccountId
              AccountType
      job_title textbox
      textbox2
      textbox3
      textbox4
    (...)

    My secondary data source for GetUserProfileByName is the standard structure everyone's familiar with.

    This is what I am coding: 

    public void selector_table_Changed(object sender, XmlEventArgs e)

    {

    string id = string.Empty;

    string title = string.Empty;

    XPathNavigator secondary = DataSources["GetUserProfileByName"].CreateNavigator();

    XPathNavigator main = MainDataSource.CreateNavigator();

    id = main.SelectSingleNode("/my:myFields/my:selector_table/my:gpContactSelector/my:Person[1]/my:AccountId", NamespaceManager).Value;

    secondary.SelectSingleNode("/dfs:myFields/dfs:queryFields/s0:GetUserProfileByName/s0:AccountName", NamespaceManager).SetValue(id);

    DataSources["GetUserProfileByName"].QueryConnection.Execute();

    title = secondary.SelectSingleNode(@"/dfs:myFields/dfs:dataFields/s0:GetUserProfileByNameResponse/s0:GetUserProfileByNameResult/s0:PropertyData[s0:Name = ""Title""]/s0:Values/s0:ValueData/s0:Value", NamespaceManager).Value;

    e.Site.SelectSingleNode("/my:myFields/my:selector_table[1]/my:job_title", NamespaceManager).SetValue(title);

    }

    Thank you in advance. 

     

  • 08-12-2008 11:00 AM In reply to

    • altja
    • Not Ranked
      Male
    • Joined on 07-02-2008
    • Grand Rapids, MI
    • Posts 10

    Re: How to force click "Check names" in a contact selector control

     

     

    What does the GetUserProfileByName datasource look like.  I am not familar with it.  If you would be so kind to include that i would be interested.

     

    However, I assume your problem is my:Person[1].  That is going to be only the first person.  I realize you are in a repeating table, but you are not distinguishing whihc row you are using.

  • 08-12-2008 11:08 AM In reply to

    Re: How to force click "Check names" in a contact selector control

    GetUserProfileByName is a property associated with the MOSS out of the box userprofileservice web service.  I established it as receive data.  Anyway, maybe part of my problem is in the way I declared the primary source xpathnavigator object?

  • 08-12-2008 12:49 PM In reply to

    Re: How to force click "Check names" in a contact selector control

    To distinguish which row I am using, can I do something like....

    XPathNavigator mainsource = e.Site;

    mainsource.MoveToParent();

    ???

    Then do the rest of the value assignations.   I tried this approach without success.   So, how do I distinguish rows in a repeating table scenario?   Thanks.

  • 08-12-2008 04:29 PM In reply to

    Re: How to force click "Check names" in a contact selector control

    My level of frustration is now beyond what is acceptable.  I have changed my handler object and code to the following and still no results (that is, I can auto-populate my job_title textbox for the first row but not for subsequent rows).  This in a browser-enabled form.

    public void InternalStartup()

    {

    EventManager.XmlEvents["/my:myFields/my:selector_table/my:selector_control/my:Person"].Changed += new XmlChangedEventHandler(selector_table_selector_control_Person_Changed);

    }

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

    public void selector_table_selector_control_Person_Changed(object sender, XmlEventArgs e)

    {

    if (e.Operation == XmlOperation.ValueChange || e.Operation == XmlOperation.Insert)

    {

    XPathNavigator secondaryDS = DataSources["GetUserProfileByName"].CreateNavigator();

    XPathNavigator secondaryRef = secondaryDS.SelectSingleNode("/dfs:myFields/dfs:queryFields/s0:GetUserProfileByName/s0:AccountName", this.NamespaceManager);

     

    XPathNavigator mainDS = e.Site;

    mainDS.MoveToParent();

    XPathNavigator mainRef = mainDS.SelectSingleNode("//my:myFields/my:selector_table/my:selector_control/my:Person/my:AccountId[1]", this.NamespaceManager);

    secondaryRef.SetValue(mainRef.Value);

    DataSources[
    "GetUserProfileByName"].QueryConnection.Execute();

    secondaryRef = secondaryDS.SelectSingleNode(@"/dfs:myFields/dfs:dataFields/s0:GetUserProfileByNameResponse/s0:GetUserProfileByNameResult/s0:PropertyData[s0:Name = ""Title""]/s0:Values/s0:ValueData/s0:Value", this.NamespaceManager);

    mainRef = mainDS.SelectSingleNode("//my:myFields/my:selector_table/my:job_title[1]", this.NamespaceManager);

    mainRef.SetValue(secondaryRef.Value);

    }

    }

    I need to get this done real soon.  Thanks.

    PS: I have worked with xpath before but never as painfully as here.  Not sure what's up.

  • 08-12-2008 07:32 PM In reply to

    Re: How to force click "Check names" in a contact selector control

    Hey, just a thought -- on all of the nodes where you are using [1] to grab the node, you are grabbing the first one.... you could try [last()] to get the last node...I'm not sure off hand if [last()] is one of those "not allowed in a browser form" functions, but may be worth a try....

    Hilary Stoupa

  • 08-13-2008 08:15 AM In reply to

    Re: How to force click "Check names" in a contact selector control

    Thanks, Hilary, but no luck once again.  I wish someone would answer some or all of the questions I posted yesterday (further up).  And if someone here has actually accomplished what I am trying to do, I need to hear a clear solution instead of vague suggestions.  Please.

  • 08-14-2008 02:11 PM In reply to

    Re: How to force click "Check names" in a contact selector control

    In reference to your earlier questions:

    I think that at first, you were not using the correct Changed event -- you'd attached it to a group higher than the one you needed. It seems in your post of 08-12-2008 04:29 PM you are attached to the correct changed event, that for your repeating group "Person".

    The event will run every time a row is inserted or deleted. If you only have code you want to have run during one or the other operation, you can wrap it in an "if" statement, like so:

    if (e.Operation.Equals("Insert"))
    {
        
    //code goes here
    }

    When I am in doubt about an event, when it is running, how often, etc. I use a message box to let me know:

    if (e.Operation.Equals("Insert"))
    {
        
    MessageBox.Show("In if statement");
    }

    You can also put a breakpoint in your code and watch when you hit it. That can help you see when events are being triggered.

    On to your code itself. I looked at it more closely today, and I think this is what you need:

    id = main.SelectSingleNode("/my:myFields/my:selector_table/my:gpContactSelector/my:Person[1]/my:AccountId", NamespaceManager).Value;

    should be:

    id = e.Site.CreateNavigator().SelectSingleNode("my:AccountId", NamespaceManager).Value;

    e, the variable for the XmlEventArgs being passed into the Changed event, is aware of its location in the table. To go back up to your job title, instead of this:

    e.Site.SelectSingleNode("/my:myFields/my:selector_table[1]/my:job_title", NamespaceManager).SetValue(title);

    I think you need this:

    e.Site.SelectSingleNode("../../my:job_title", NamespaceManager).SetValue(title);

    Although I am less sure -- I always have to try several variations to get the xpath right moving back up. Of course, you can also use e.Site.MoveToParent(); to work your way back up the tree.

    Hilary Stoupa

  • 08-15-2008 07:48 AM In reply to

    Re: How to force click "Check names" in a contact selector control

    Hilary, thank you for your suggestions.  I will give them a try and report back later.

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