Help a newbie with comparing repeating table field - InfoPath Dev
in

InfoPath Dev

Help a newbie with comparing repeating table field

Last post 03-13-2012 10:33 AM by smitman34. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 08-30-2005 09:35 AM

    Help a newbie with comparing repeating table field

    Hi all,

    I have a repeating table in a secondary data source. What I need to do is compare these values to a known value, and return a boolean result.

    What's happening, is that only the first row in that repeating table is being compared.

    Here's the pertinent code:

    private string			CurrentUser;
    private IXMLDOMDocument2 ConfigForm;

    public void _Startup(Application app, XDocument doc)
    {
    thisXDocument = doc;
    thisApplication = app;

    CurrentUser = System.Environment.UserName.ToLower();
    }

    [InfoPathEventHandler(EventType=InfoPathEventType.OnLoad)]
    public void OnLoad(DocReturnEvent e)
    {
    CurrentUser = System.Environment.UserName.ToLower();

    IXMLDOMDocument2 ConfigForm = (IXMLDOMDocument2)thisXDocument.CreateDOM();
    ConfigForm.async = false;
    ConfigForm.load("Config.xml");
    ConfigForm.setProperty("SelectionNamespaces", "xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-08-17T18:16:54\"");

    SetUserRole(CurrentUser);
    }


    public void SetUserRole(string UserAlias)
    {
    string UserNode = ConfigForm.selectSingleNode("/my:Config/my:Administrators/my:Administrator/my:Admin-Alias").text.ToLower();

    if(UserNode == CurrentUser)
    thisXDocument.Role = "Admin";
    else
    thisXDocument.Role = "Requestor";
    }



    I'm pretty new to this InfoPath thing, so go easy on me :)

    Thanks!
    -DC Ross
  • 09-01-2005 10:07 AM In reply to

    Re: Help a newbie with comparing repeating table field

    This is because you are using select"SINGLE"node... which does just that. It selects a "single" node... typically the first one.

    One way around that is to use a filter in your XPath, similar to this:

    IXMLDOMNode User = ConfigForm.selectSingleNode("/my:Config/my:Administrators/my:Administrator/my:Admin-Alias[. = '" + UserAlias + "']");
    if(User != null)
    UserNode = User.text.ToLower();

    This will find the first my:Admin-Alias that has a value equal to UserAlias. If null is returned, then no match was found.

    What I'm not accounting for in my example above is for case differences... so if in the XML you have "Foo" and UserAlias is "foo", there won't be a match. You can try using translate() to resolve that... For example, assuming UserAlias is already in all lower-case:

    ...my:Admin-Alias[translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = '" + UserAlias + "']"...

    Good luck!


    Greg Collins [InfoPath MVP]
    InfoPath Dev
  • 09-01-2005 10:57 AM In reply to

    Re: Help a newbie with comparing repeating table field

    Thank you very much for your reply, Greg. I appreciate your help, but...

    I inserted the code you provided, and I'm still getting the same results as I was before - only the first row in the repeating table is being compared.

    Here's the new SetUserRole method:

    public void SetUserRole(string UserAlias)
    {
    IXMLDOMNode UserNode = ConfigForm.selectSingleNode("/my:Config/my:Administrators/my:Administrator/my:Admin-Alias[translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = '" + UserAlias + "']");

    if(UserNode != null)
    thisXDocument.Role = "Admin";
    else
    thisXDocument.Role = "Requestor";
    }


    Here's a sample of my data:

    <my:Config xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-08-17T18:16:54" xml:lang="en-us">
    <my:Administrators>
    <my:Administrator>
    <my:Admin-FullName>DC Ross</my:Admin-FullName>
    <my:Admin-Alias>dcross</my:Admin-Alias>
    </my:Administrator>
    <my:Administrator>
    <my:Admin-FullName>John Smith</my:Admin-FullName>
    <my:Admin-Alias>jsmith</my:Admin-Alias>
    </my:Administrator>
    </my:Administrators>
    </my:Config>

    If John Smith were to view the form, he would be assigned the role of "Requestor", not "Admin".

    Thank you in advance,
    -DC Ross
  • 09-06-2005 06:58 PM In reply to

    Re: Help a newbie with comparing repeating table field

    Never mind, I realized that the data wasn't being retrieved.

    Thank you very much for your help,
    -DC Ross
  • 03-13-2012 10:33 AM In reply to

    Re: Help a newbie with comparing repeating table field

    Hi DC,

    I'm no expert here either but I think what you need to do is loop through the repeating table.

    I'm in a similiar situation and I'm trying this:

    DataSource ds = this.DataSources["SecondarySourceName"];

    XPathNavigator NavBTIN = ds.CreateNavigator();

    XPathNodeIterator rows = NavBTIN.Select("Path to your field", NamespaceManager);

    while (rows.MoveNext())

    {

    if(UserNode == CurrentUser)
    thisXDocument.Role = "Admin";
    else
    thisXDocument.Role = "Requestor";

    }

    The challenge I have is I only want to evaluate on the first occurance in the repeater and then I want to get out.

    Maybe this helps you, give it a try.

    Maybe you can help me with my problem: http://www.infopathdev.com/forums/p/22078/76356.aspx#76356


     

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