How to do complex formatting rules - InfoPath Dev
in

InfoPath Dev

How to do complex formatting rules

Last post 02-27-2014 02:47 AM by Jimmy. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 02-24-2014 05:00 AM

    • elcoms
    • Not Ranked
      Male
    • Joined on 08-19-2011
    • northern Germany
    • Posts 4

    How to do complex formatting rules

    I need to activate a deactivated a button with a complex rule like: If (checkbox c is checked) { if (People Field P1 contains current user) { activate current button } } else { if (People Field P2 contains current user) { activate current button } } How is it possible without code? Thanks!
    Filed under:
  • 02-24-2014 06:05 AM In reply to

    Re: How to do complex formatting rules

    How about two separate formatting rules:

    Condition: c is checked AND P1 does not contain current user
    Formatting: Disable button

    Condition: c is not checked AND P2 does not contain current user
    Formatting: Disable button

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-26-2014 08:46 AM In reply to

    • elcoms
    • Not Ranked
      Male
    • Joined on 08-19-2011
    • northern Germany
    • Posts 4

    Re: How to do complex formatting rules

    Thanks, maybe that would work, but I thought about it again and the condition is different:

    Enable button if ( (Status == 1 || status == 2) && (p1 != current user || p2 != current user )
    || (Status==3 && P1 == current user)
    || (Status = 4 && P2 == current user) )


    The problem is that it is only possible to disable a button, not to enable it. When the condition is reversed to "disable button if.." it must be one single rule because of the top level ANDs, there is also no possibility to define paranthesis in rules, at least none I know of.

    btw. what does it mean when a rule is like:
    a equals b AND
    a equals c OR
    a equals d

    does it mean
    (a==b && a==c) || a==d
    or
    a==b && (a==c || a==d)
    ?
  • 02-26-2014 09:35 AM In reply to

    • Doreen
    • Top 50 Contributor
      Female
    • Joined on 08-11-2010
    • Federal Way, WA
    • Posts 291

    Re: How to do complex formatting rules

    You might look into using xml expressions to accomplish that complexity in one condition, which I am no expert on. I think QRules could help you here.

    I would also consider looking into setting up User Roles. (I use InfoPath 2007, Tools>User Roles.  Add a role then name it anything, assign users name from Active Directory, individual or groups or if you haven't alrady set up an admin page on your form to collect current user names and add user names from the form to a role).   Create a group of users called Status1234_users or P1P2_Users that includes P1 and P2 users, then you can write individual conditions like:

    if current user's role != Status1234_users AND

    Status = 1, disable button

    ----

    if current user's role != Status1234_users AND

    Status != 2, disable button

    --- and so on

    Or adjust your logic accordingly and write 6 individual conditions (eliminate the need to use AND and OR entirely).  Play around with this to see what happens.  

    1. if status != 1 AND p1 = currentUser, disable button

    2. if status != 2 AND p2 = currentUser, disable button

    3. if status != 3 AND p1....

    4. if status != 3 AND p2...

    5. if status != 4 AND p1...

    6. if status != 4 AND p2...

    Your question about AND, OR...

    The condition you wrote means:
    if (a = both b and c) or if (a=d only), do something (your first guess was correct!). :)

  • 02-27-2014 12:12 AM In reply to

    Re: How to do complex formatting rules

    It is possible to define more complex expressions by entering your own manually, but I like to avoid that when possible because you lose the built-in checking that comes with the InfoPath designer. It is possible to define your condition in terms of disabling the button, using the following rules:

    Rule 1: Disable if Status = 1 AND p1 = current user 

    Rule 2: Disable if Status = 1 AND p2 = current user 

    Rule 3: Disable if Status = 2 AND p1 = current user 

    Rule 4: Disable if Status = 2 AND p2 = current user 

    Rule 5: Disable if Status = 3 AND p1 != current user 

    Rule 6: Disable if Status = 4 AND p2 != current user 

     

    To answer your second question, as with most programming languages, AND has a higher associativity than OR, so your example would be equivalent to (a = b and a = c) or a = d

    One other option is to have a non-displayed field called something like EnableButton, and give it a default value formula like:

     ((Status = 1 or Status = 2) and (p1 != current user or p2 != current user )) or (Status = 3 and P1 = current user)
     or (Status = 4 and P2 = current user)

     Then you can disable the button depending on whether that field is true or false.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-27-2014 02:10 AM In reply to

    • elcoms
    • Not Ranked
      Male
    • Joined on 08-19-2011
    • northern Germany
    • Posts 4

    Re: How to do complex formatting rules

     Hi,

     thank you. A non displayed field would be handy in this case, but since it is a SharePoint list form, every extra field results to an extra column in the list - not good.

    The manual rule definiton sounds interesting, how does it work?  I simplified the condition for this example. In fact, I got 8 status values, and 5 different rule sets (condition matrices). One of the rule sets needs to be applied to each of the 21 controls of the form.
    So copy/paste of complete rule sets is quite essential for not going nuts.

     

       

  • 02-27-2014 02:47 AM In reply to

    You can manually enter a formula by selecting "The expression" from the left dropdown in the condition builder, but if you're going to be applying these complex formatting rules to lots and lots of controls, that's all the more reason not to be copying a manually-constructed expression from place to place.

    I can understand you not wanting to add extra fields, though, so here's a sample form that uses a similar trick without requiring extra fields to be added to the main data source.

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