Code to Iterate through Secondary DataSource - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Code to Iterate through Secondary DataSource

Last post 12-11-2008 10:57 AM by mjarrett. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 12-10-2008 09:44 AM

    • mjarrett
    • Not Ranked
      Male
    • Joined on 11-06-2008
    • Lansing, MI
    • Posts 8

    Code to Iterate through Secondary DataSource

    Hi all

     I am using ILoveSharePoint's GetGroupsFromCurrentUser webservice which returns all SharePoint groups that the user is in. Anyhow, this is a secondary datasource. I need help writing the code to iterate through this repeating field. Then, I need to unhide a section based on whether or not they are in the group.

     I have tried to populate a drop-down list with this information and use "Contains", "Is Equal to", "is present" to control the conditional formatting but it does not work.

    I was thinking with something along the lines of <pseudo code>:

    foreach(Group in GroupList)
    {
       If (Group == "Human Resources")
          {
             show hidden section
           }
    }

    </pseudo code>

    But I am not very proficient with C# and the XPathNavigators and such. Any help would be GREAT! Thanks in advance!

     

    Filed under: , ,
  • 12-10-2008 04:16 PM In reply to

    Re: Code to Iterate through Secondary DataSource

    Code for this would not require iteration.  It would look like this:

    XPathNavigator iLoveSharePointSource = DataSources["GetGroupsFromCurrentUser"].CreateNavigator();
    if (iLoveSharePointSource.SelectSingleNode("//s1:UserGroups[s1:string = 'Human Resources']", NamespaceManager) != null)
    {
         // do stuff
    }

    You might need to change the GetGroupsFromCurrentUser and s1, depending on what those are called in your form.

    But it sounds to me like you just want to show or hide a section, which would be done in conditional formatting, not code.  Just hide the section based on this expression:

    not(xdXDocument:GetDOM("GetGroupsFromCurrentUser")//s1:UserGroups[s1:string = "Human Resources"])

    Again, you may need to adjust the bold parts.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-10-2008 09:39 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Code to Iterate through Secondary DataSource

    Hello,

    We can hide the section using expression as Jimmy said. If you want you can add one more field in schema and set the value is true for show the section otherwise hide the section. This new field value we have to set in code based on your condition.

  • 12-11-2008 10:57 AM In reply to

    • mjarrett
    • Not Ranked
      Male
    • Joined on 11-06-2008
    • Lansing, MI
    • Posts 8

    Re: Code to Iterate through Secondary DataSource

    Works perfectly! Thank you!

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