Conditional Expression OR security trimming controls - InfoPath Dev
in

InfoPath Dev

Conditional Expression OR security trimming controls

Last post 05-14-2010 10:24 AM by Jimmy. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 05-14-2010 08:01 AM

    Conditional Expression OR security trimming controls

    Not sure if this goes under code or controls. 

    Here's the situation I need to disable certain controls on my for based on user that is logged on to the PC.  So in my for load event I have some code that gets the users AccountName and puts it in a textbox:
    XPathNavigator root = this.MainDataSource.CreateNavigator();
    GetUserInfoWS.
    UserProfileService profileService = new sustainabilityForm.GetUserInfoWS.UserProfileService();
    profileService.UseDefaultCredentials =
    true;
    GetUserInfoWS.
    PropertyData[] userProps = null;
    try
    {
    userProps = profileService.GetUserProfileByName(
    null);
    }
    catch { }
    if (userProps == null || userProps.Length == 0) return;
    GetUserInfoWS.
    ValueData[] values = userProps[1].Values;
    XPathNavigator node = null;
    node = root.SelectSingleNode(
    "/my:myFields/my:MyCurrentUser", NamespaceManager);
    node.SetValue(values[0].Value.ToString());

    Then on the controls that need to be disabled I have a conditional condition that compares what I have in the textbox with what is in a custom list I created called SustainApprovers...like this:

    MyCurrentUser is not equal to translate(eval(eval(SustainApprovers, "@Person"), ".."), "abcdefghijklmnopqrstuvwyxz", "ABCDEFGHIJKLMNOPQRSTUVWYXZ")

    Okay so here is the problem.  If I have the second part of the condition as translate(my:myFields/my:dataFields/my:Person, "abcdefghijklmnopqrstuvwyxz", "ABCDEFGHIJKLMNOPQRSTUVWYXZ") It does not go through the the custom list and query each row, it only looks at the top row....so I added in the double eval and while this gets the whole list it still does not equal true.  Is there a better way to security trim controls in InfoPath?

     Thanks

    Tom

  • 05-14-2010 09:31 AM In reply to

    Re: Conditional Expression OR security trimming controls

    Please try this formula:

    not(SustainApprovers/@Person[msxsl:string-compare(., MyCurrentUser, '', 'i') = 0])

    You'll of course need to provide the full paths to @Person and MyCurrentUser, not these simplified versions.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-14-2010 09:52 AM In reply to

    Re: Conditional Expression OR security trimming controls

    No however I did change it a little to:

    not(dfs:myFields/dfs:dataFields/dfs:SustainApprovers/@Person[msxsl:string-compare(., translate(/my:myFields/my:MyCurrentUser, "abcdefghijklmnopqrstuvwyxz", "ABCDEFGHIJKLMNOPQRSTUVWYXZ"), "", "i") = 0])

    I need to change MyCurrentUser to lower case so that it will match...or does that not matter?

    Will this still read in all the rows from the custom list to see if there are any matches.....or do I need to include the double eval?

  • 05-14-2010 10:24 AM In reply to

    Re: Conditional Expression OR security trimming controls

    Yes, it will work if there is any match in the list, and there's no need to use that translate() hack.  The msxsl:string-compare is there to perform a case-insensitive string comparison.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.