How to hide a section of a form depending on User.


This has been something I’ve been looking to figure out for a while. If anyone knows a better way, please let me know. I’m kind of stuck with a mostly basic setup, but we were lucky enough to be able to do some InfoPath form editing at work.

Basic gist of what I was hoping to do is be able to hide several form elements depending on who is logged in. While I had hoped to be able to do this with a group, or a more dynamic way of editing said people…. I’m happy to have figured it out.

In the past I tried working on something similar to this but never was successful. Just a week or two ago someone had asked me if I had any ideas. I started replying, “Actually I’ve tried it, but let me take a peak at this InfoPath book I won at SPTechCon San Fran and see if I find anything.” The book I’m referring to is called InfoPath with SharePoint 2010 by Steven Mann. I flipped through a few pages and stumbled upon a function for UserName, which I’ve seen.. but decided.. well maybe if I can throw that into a field and compare that for the rule, maybe I can hide a section.

Sure enough, that seemed to work. So here is a quick work around I was able to use and I’m sure others will be able to as well. I’m sure there’s gotta be a better way, but until I learn it, this will do!

I’m using a quick list I created called “HelpRequest”. Nothing special. Title, Description, and a Request Status are my columns. Request Status is a choice field of “Received, In Progress, Completed, Rejected, etc”. I only want myself to be able to edit that field. So let’s get started.

  1. I’m going to open up the form with InfoPath via the List Ribbon and “Customize Form” with the InfoPath logo.
  2.  Next, I’m going to insert  a section below the current form. You can do this by going to the bottom of the Controls part of the Home Ribbon.
  3. Then I’m going to cut/paste the Request Status field into the newly created Section.
  4. Next, I’m going to click on “Add Field” in the Fields menu on the bottom right.
  5. Now I’m going to create a field called “UserName” and click OK. Once it’s created it’ll appear in the Fields Menu on the right. Double click your newly created “UserName” field. Go down to the Default Value at the bottom and click on fx for functions > click insert function > User > userName > OK > OK > OK. (You could have probably just typed in userName() but I think knowing this might inspire you to check out other functions at some point.) Basically, what we did is made the default value the ID of whoever is logged in. We’ll use it to compare later for our Rule.
  6. Drag the UserName field out into the section below the Request Status (You may want to insert a row in the table below if you want it to look uniform). Now we can setup the rule.
  7. Click on “Manage Rules” in the Home Ribbon. Click on the edge of the Section for focus. Now go to the Rules menu and click New > Formatting. Click on Condition and choose your UserName column, is not equal to, and then in the last drop down, select “Type tex” and type in your ID as it would show. For example, on this site I’m creating the demo with, dbannister is my id. Then click OK. If you are unsure of which it would be, go publish your InfoPath form (before you write the rule) and see what your ID shows as in the UserName field. The rule should look similar to:
  8. Lastly, click back over to the rules and select “Hide this control”. Publish the form. We have just set that section to only show up if they are “dbannister”. Otherwise it’ll be hidden.

I assume you can insert other user’s into that rule, just be sure to test to make sure you got your and/ors right and that it’s working as expected. Good luck!