Jul 14, 2008

Infopath - Switch View Depending on the Current User's Role

Did you ever need to switch the view depending on the current user's role in an browser enabled Infopath 2007 form? Good luck!

The process presents a very common business scenario, but unfortunately also a very tricky one. The local Infopath client has a built-in mechanism to do that, but there isn't any for browser enabled forms running on Infopath Form Services.

If you googel for a solution, you'll maybe find an article from the Infopath team. They suggest to use an XML file containing all rules and users and store it within the form template. That would work! But, the downside of this approach is that you have to change the form template every time a user's role changes. This is inapplicable for large scale enterprises!

So my idea was to switch the view on the load event of the form depending on the user's SharePoint group using SPContext. Sounds good, but doesn't work, because you aren't able to switch the view programmatically  on the load event- just great!

Next try: Because I'm a smart ass;-) I've started to try the built-in SharePoint Web Service (usergroup.asmx) to get the user's groups. The "GetGroupCollectionFromUser" method returns an "xsd:any"-node, doesn't work with Infopath - tiresome! Okay, there would be a chance to get around this in trying to modify the automatically generated schemas from the wsdl in the XSN- I don't like that.

Now, I've had enough! I've just written my own SharePoint Web Service. It's a very simple service with only one method, returning the SharePoint groups from the current user. Quiet simple, but effective! The Web Service works exactly as any built-in SharePoint Web Service, expects that it works with Infopath :-) 

You can download the web service (sources and solution package) on my CodePlex project "I Love SharePoint".

  • Execute the deploy script (deploy.bat). Don't get frightened, the script first tries to uninstall the solution. This will fail the first time you're running.
  • Paste the following url in your browser to check that the service is running: http://localhost/_vti_bin/ILoveSharePoint/UserService.asmx
  • You're done, now try it in Infopath:
    • Open an existing form template or create a new one
    • Extras->Data Sources->Add
    • Choose new connection to receive data
    • Enter the url of the service: http://localhost/_vti_bin/ILoveSharePoint/UserService.asmx -> next
    • Select "GetGroupsFromCurrentUser" -> next -> next -> finish
    • After that select Data Sources in the task pane and choose the one you've just created
    • Expand the child nodes of dataFields until you find the UserGroups node
    • Drag the node on your form and choose section with controls
    • Now you're done. Click the preview icon...

The url pattern for the web service is as follows:


The [site] and [subsites] placeholders define the site you want to get the current user groups from.

You can use the service with the Infopath's rules, perhaps to:

  • Switch the view depending on the user's SharePoint group on the load event of the form
  • Show or hide controls depending on the user's group using conditional formatting

Any questions or ideas? Leave a comment...

Have fun,



Johnny said...

Thx to you for this solution. It's very good and solves a lot of problems i had, when i wanted to use permission-handling in browser-based forms with approval-steps. Keep it up!

Maneer said...

That was great and works perfectly.
But i have a minor issue, if a user is part of multiple groups then your solution reflects the group name coming first alphabatically. Do you have any workaround for displaying multiple groups?


Christian said...

Hi Maneer,
that's right. The service loops through all groups of the current user and adds them to the result.
What's your scenario?
Bye, Christian

galla said...

Great solution.but i have one problem please clarify.iam hiding the sections on InfoPath Form depending on UserGroups.It's working fine. but when i open the fublished form,the hiden sections are visible for all user's.It's might be data is not refreshing.please clarify me.

Christian said...

Hi galla,

My first idea is does Infopath Form Services supports to hide sections? Please check that you only use compatible controls. http://office.microsoft.com/en-us/infopath/HP100340241033.aspx Regards this link it should support sections. This isn't an service issue, this seems to be a browser form issue. You can try to change the controls postback behaviors in the control's properties.
Bye, Christian

Burak Donbay said...

Thanks for the article.
It's perfect!!!

.NET Dev said...

Great !!!
But I have one issue:
I added my active directory group in the sharepoint group. So, it is unable to detect the sharepoint group.

Any Solution?

.NET Dev

Anonymous said...

How did you create this custom webservice? Did you use WSS 3.0 SDK?
Please let me know step by step. what components are needed to be installed?


Christian said...


read on the MSDN "Walktrough: Creating a Custom Web Service" http://msdn.microsoft.com/en-us/library/ms464040.aspx
Hope this helps.

Bye, Christian

Maneesh said...

.NEt Dev,
Please use following link to get AD groups for a user.
http://urenjoy.blogspot.com/2009/04/getting-active-directory-groups-from.html and use these AD groups as a member of sharepoint groups.

Winfried said...

Super WebService!

Ist es möglich einen beliebigen AccountName als Parameter zu übergeben? Ich möchte die Gruppenmitgliedschaften eines per ContactSelector ausgewählten Benutzers abfragen. Oder gibt es dafür eine Alternative?



Anonymous said...

I've got an 5566 event error: access is denied. What am i missing?

Alison said...

Has anyone got this working on SP 2010 ?


Akalanka said...

This works for sharepoint 2010

Naresh said...

great job!!! it helped a lot.

Anonymous said...

you're definetely the man!!! u justed saved my week :)


Anonymous said...


I am using your web service to display SharePoint Groups and then hide controls (Sections) depending on what group you belong to. I am using SharePoint 2010 and InfoPath 2010. It works fine when I am in preview mode in InfoPath, however, when I publish the form and open a new document in the form library, there are no groups showing.
Can you please advise?



Anonymous said...

Mine does not work at all. I am trying to diplay a view based on what group they are in and it seems it is not reading the user groups. I am basing it on a Form load rule if string is equal to Owners then show the Edit View and it is not working.

Mendo_Man said...

Brilliant solution, easy to install and use. Other solutions were either code or altering the form's source files. Thumbs up

Anonymous said...

How do I use this web service? I know how to add the data connection, but is there an example of how to actually utilize this solution in practice? I would like to load views based on groups on form load. Is there an example I can follow?

electronic seal said...

Thank you so much for taking the time to share this information. A great read. I’ll certainly be back.

Hug Day said...

happy hug day 2016
happy hug day 2016 Date SMS Messages Quotes
How Hug Day Is Celebrated
Happy hug day sms

风骚达哥 said...

20160423 junda
air jordans
cheap oakley sunglasses
kate spade outlet
adidas stan smith
ray ban sunglasses
michael kors outlet
nike air max shoes
cheap omega watches
yeezy boost 350
michael kors outlet online
michael kors outlet online
nike free runs
air jordan uk
michael kors outlet online
pandora charms
ray ban outlet
calvin klein outlet
fitflops sale clearance
toms outlet
nike huarache white
sac longchamp
toms outlet
michael kors outlet clearance
bottega veneta outlet
armani watches
gucci handbags
nike blazer
oakley sunglasses
true religion jeans
cheap jordans
ray bans
bottega veneta handbags
jimmy choo outlet
oakley sunglasses
prada outlet
reebok shoes
true religion
burberry outlet

Yuanyuan Lin said...

7.14llllllyuan"oakley sunglasses"
"louboutin pas cher"
"kate spade handbags"
"hollister clothing"
"links of london jewellery"
"toms shoes"
"longchamp outlet"
"versace sunglasses on sale"
"toms outlet"
"tory burch outlet"
"air max uk"
"ferragamo shoes"
"michael kors handbags"
"cartier watches for sale"
"mulberry handbags"
"tods shoes"
"tods outlet online"
"tiffany jewellery"
"coach outlet online"
"toms outlet"
"ray-ban sunglasses"
"oakley sunglasses wholesale"
"rolex watches"
"ferragamo shoes"
"ferragamo shoes"
"michael kors outlet online"
"burberry outlet sale"
"lebron shoes"
"fitflops outlet sale"
"true religion jeans"
"coach outlet store"
"coach outlet"
"juicy couture tracksuit"
"michael kors factory outlet"
"oakley sunglasses sale"

Justin said...

The Barron's Plan approaches the issue starting from the top. Fix the banks; make them adjust contracts; get income moving; get loaning restarted. The issue is this is the old arrangement. It won't work; it can't work. check cashing

Justin said...

As we move into the final lap, the marking docs are dispatched out to escrow the client is planned to visit the escrow office for record execution. Docs touch base at escrow who now puts these bits of paper all together, get's beginning and end marked and authenticated legitimately, and returns back to the wholesaler/moneylender. aaa1autotitleloans.com/chicago

Fangyaya said...

michael kors purses
christian louboutin outlet
burberry handbags
coach outlet online
fitflop clearance
jordan 3s
michael kors
michael kors outlet
air jordan 8
replica rolex watches
adidas outlet store
michael kors outlet clearance
retro 11
cheap true religion jeans
cheap true religion
nike air max uk
replica rolex watches
christian louboutin shoes
supra footwear
louis vuitton bags
designer handbags
polo ralph lauren
cheap basketball shoes
adidas originals
coach outlet store online
coach outlet
cheap jordan shoes
oakley vault
jordan retro 4
coach factory outlet online
louis vuitton outlet
air jordan shoes
ed hardy outlet
gucci handbags
adidas yeezy
kobe shoes
discount jordans
cheap jordans
oakley sunglasses
coach factory outlet online

dada24 Xu said...

cheap oakleys
ralph lauren pas cher
canada goose
michael kors outlet clearance
true religion outlet
armani exchange
gucci outlet
ed hardy
ugg boots
ray ban sunglasses

raybanoutlet001 said...

michael kors bags
fitflops sale
ed hardy uk
hermes belts
ugg outlet
christian louboutin shoes
adidas nmd
ugg boots
adidas nmd
jordan shoes

Best Home Improvement Company Westchester County said...

Ajrin Construction Inc. is a privately owned firm and has been providing home improvement and remolding services to clients all across the boroughs of Westchester County NY. Best Home Improvement Company Westchester County

Nikshit Narula said...

Awesome Post!
Check out Reason Beind diwali celebrations
Also download latest movie THE FATE OF THE FURIOUS 2017 NEW HDCAM HINDI + ENGLISH
Also Read trending Story Beach Photos
Also Check out Latest Government Job of ASRB Recruitment 2017

Sankar lp said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

khairy said...

شركة مكافحة حشرات بالمدينة المنورة
شركة كشف تسربات بالمدينة المنورة
شركة تنظيف شقق بالمدينة المنورة
شركة تنظيف موكيت بالمدينة المنورة
شركة تنظيف مجالس بالمدينة المنورة
شركة تنظيف منازل بالمدينة المنورة
شركة تنظيف كنب بالمدينة المنورة
شركة تنظيف فلل بالمدينة المنورة

raybanoutlet001 said...

kate spade outlet online
oakland raiders jerseys
kate spade outlet online
ralph lauren uk
kate spade outlet online
louboutin shoes
nike factory outlet
moncler outlet
ralph lauren outlet
jacksonville jaguars jersey

风骚污男 said...

20180601 junda
nuggets jerseys
canada goose jackets
wizards jerseys
ugg outlet
longchamp outlet
ugg outlet
fred perry polo shirts
polo ralph lauren
birkenstock outlet
g-star jeans

Yaro Gabriel said...

nike factory
louboutin shoes
nike soldes femme
ugg boots on sale 70% off
fitflops sale clearance
salomom shoes
nike presto
supreme shirt
christian louboutin shoes

5689 said...

louboutin shoes
christian louboutin
ralph lauren polo
pandora charms
christian louboutin
christian louboutin outlet
canada goose clothing
canada goose outlet
canada goose outlet

Yaro Gabriel said...


christian louboutin
ferragamo belt
christian louboutin
ralph lauren polo
coach outlet
canada goose jackets

j joody said...





tamilsasi said...

Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage
contribution from other ones on this subject while our own child is truly discovering a great deal.
Have fun with the remaining portion of the year.
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training

Maria said...

I started playing at simply casino casino after reading reviews from other players and I see that it’s not for nothing. Judging by the number of reviews on the Internet, it seems that only the lazy one did not play here)) Well, by the number of reviews and topics on the forums one can definitely say that this is one of the most popular players.

Chris Hemsworth said...

The article is so informative. This is more helpful for our
software testing training courses
selenium course Thanks for sharing

Riya Raj said...

The way you have conveyed your blog is more impressive.... good blog...
JAVA Training in Chennai
JAVA Course in Chennai
Java Training
Java classes in chennai
JAVA Training in Annanagar
java training in vadapalani
Digital Marketing Course in Chennai
Python Training in Chennai
Big data training in chennai
Selenium Training in Chennai

Kayal m said...

The article is so informative. This is more useful for me. Keep doing great work and a good job.

Tableau Training in Chennai
Tableau Course in Chennai
Unix Training in Chennai
Embedded System Course Chennai
Oracle Training in Chennai
Social Media Marketing Courses in Chennai
Oracle DBA Training in Chennai
Pega Training in Chennai
Linux Training in Chennai
Job Openings in Chennai

shivam said...

Flying Shift - Packers & Movers in Bhopal

watson said...

Very interesting and useful blog. digital marketing training in bangalore

Customer relationship management said...

Your articles really impressed for me,because of all information so nice.servicenow training in bangalore

Customer relationship management said...

These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post.opennebula training in bangalore

Customer relationship management said...

I gathered a lot of information through this article.Every example is easy to undestandable and explaining the logic easily.openstack training in bangalore

Customer relationship management said...

Very useful and information content has been shared out here, Thanks for sharing it.salesforce developer training in bangalore

Customer relationship management said...

This is really an awesome post, thanks for it. Keep adding more information to this.vmware training in bangalore

watson said...

Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind.citrix training in bangalore

watson said...

thank you so much for this nice information Article, Digitahanks for sharing your post with us.WEBMETHODS training in bangalore

watson said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful. PEGA PPRC training in bangalore

watson said...

This is amazing and really inspiring goal.Hadoop Training in Bangalore

watson said...

I have read your blog its very attractive and impressive. I like it your blog.Informatica Training in Bangalore

watson said...

Great post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledge.IMSBI Training in Bangalore

Customer relationship management said...

Really it was an awesome article,very interesting to read.You have provided an nice article,Thanks for sharing.angular 7 training in bangalore

Customer relationship management said...

Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving.sap s4 hana simple finance training in bangalore

Customer relationship management said...

Linking is very useful thing.you have really helped lots of people who visit blog and provide them use full information.javascript training in bangalore

Customer relationship management said...

Very useful and information content has been shared out here, Thanks for sharing it.sap hr training in bangalore

Customer relationship management said...

This is really an awesome post, thanks for it. Keep adding more information to this.html training in bangalore

Softgen Infotech said...

I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing.

Softgen Infotech is the Best Oracle Training institute located in BTM Layout, Bangalore providing quality training with Realtime Trainers and 100% Job Assistance.

watson said...

thank you so much for this nice information Article, Digitahanks for sharing your post with us.Real Time Experts training center bangalore

watson said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful . student review for Realtime Experts marathahalli bangalore

watson said...

This is amazing and really inspiring goal.Real Time Experts Training in Bangalore

watson said...

I have read your blog its very attractive and impressive. I like it your blog.Real Time Experts Training in Bangalore center address bangalore

Softgen Infotech said...

Thank you so much for the great and very beneficial stuff that you have shared with the world.

Softgen Infotech have the best Python Training in Bangalore . Any professional who is looking out to switch their career can enroll with us.

eTechno Soft Solutions said...

wonderful thanks for sharing an amazing idea. keep it...

Best SAP MM Training in Bangalore- eTechno Soft Solutions is a leading SAP MM Training Institute in Bangalore offering extensive SAP MM Training by Real-time Working Professionals along with 100% placement support, Booka Free Demo!