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:

http://[host]:[port]/[site]/[subsites]/_vti_bin/ILoveSharePoint/UserService.asmx

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,

Christian

90 comments:

Anonymous 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!
Greetings

Anonymous said...

Thanks
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?

Maneer

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

nagesg 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?

Thanks
.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?

Thanks

Christian said...

Hi,

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?

Gruß

Winnie

Anonymous said...

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

Alison A said...

Hi,
Has anyone got this working on SP 2010 ?

Thanks

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 :)

GREAT JOB!!!

Anonymous said...

Hi,

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?

Thanks

Padraic

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.

Unknown said...

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

xjd7410@gmail.com 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
hollister
bottega veneta handbags
jimmy choo outlet
oakley sunglasses
converse
prada outlet
reebok shoes
true religion
burberry outlet

Unknown 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"
7.14

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
20168.8chenjinyan

Unknown 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
2016921caiyan

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

Unknown 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 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...

zzzzz2018.5.9
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

Unknown 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

Unknown said...

www0816
nike factory
reebok
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...

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

Unknown said...

www11.17




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

Unknown said...



https://www.rashed-kw.com/مكافحة-حشرات-بالكويت/


https://www.rashed-kw.com/نقل-عفش-بالكويت/


https://www.rashed-kw.com/شركة-تنظيف-بالكويت/

https://www.rashed-kw.com/تنظيف-سجاد-بالكويت/
https://www.rashed-kw.com/فني-صحي-بالكويت/

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!

sasi said...

This was an excellent post and very good information provided, Thanks for sharing.
Python Training in Chennai
Python Training in Bangalore
Python Training in Coimbatore
Python course in bangalore
angular training in bangalore
web design training in coimbatore
python training in hyderabad
Python Course in Coimbatore

Softgen Infotech said...

Hats off to your presence of mind...I really enjoyed reading your blog. I really appreciate your information which you shared with us.

Best SAP Training in Bangalore
Best SAP ABAP Training in Bangalore
Best SAP BASIS Training in Bangalore
Best SAP FICO Training in Bangalore
Best SAP MM Training in Bangalore
Best SAP SD Training in Bangalore
Best SAP HR HCM Training in Bangalore

Softgen Infotech said...

I am happy for sharing on this blog its awesome blog I really impressed. Thanks for sharing. Great efforts.

Best SAP HANA Training in Bangalore
Best SAP HANA Admin Training in Bangalore
Best SAP GRC Training in Bangalore
Best SAP S4 HANA Training in Bangalore
Best SAP S4 HANA Simple Finance Training in Bangalore
Best SAP S4 HANA Simple Logistics Training in Bangalore

My Class Training Bangalore said...

Such a great word which you use in your article and article is amazing knowledge. thank you for sharing it.

Best SAP Training in Bangalore
Best SAP ABAP Training in Bangalore
Best SAP FICO Training in Bangalore
Best SAP HANA Training in Bangalore
Best SAP MM Training in Bangalore
Best SAP SD Training in Bangalore

My Class Training Bangalore said...

Really i appreciate the effort you made to share the knowledge. The topic here i found was really effective...

Best SAP HR Training in Bangalore
Best SAP BASIS Training in Bangalore
Best SAP HCM Training in Bangalore
Best SAP S4 HANA Simple Finance Training in Bangalore
Best SAP S4 HANA Simple Logistics Training in Bangalore

amit tavva said...

keep up the good work. this is an Assam post. this to helpful, i have reading here all post. i am impressed. thank you. this is our digital marketing training center. This is an online certificate course
digital marketing training in bangalore | https://www.excelr.com/digital-marketing-training-in-bangalore

Customer relationship management said...

Its really helpful for the users of this site. I am also searching about these type of sites now a days. So your site really helps me for searching the new and great stuff.

aws training in bangalore

aws courses in bangalore

aws classes in bangalore

aws training institute in bangalore

aws course syllabus

best aws training

aws training centers

Customer relationship management said...

This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information.

mulesoft training in bangalore

mulesoft courses in bangalore

mulesoft classes in bangalore

mulesoft training institute in bangalore

mulesoft course syllabus

best mulesoft training

mulesoft training centers

Customer relationship management said...

It is very good and useful for students and developer.Learned a lot of new things from your post Good creation,thanks for give a good information.

salesforce developer training in bangalore

salesforce developer courses in bangalore

salesforce developer classes in bangalore

salesforce developer training institute in bangalore

salesforce developer course syllabus

best salesforce developer training

salesforce developer training centers

Customer relationship management said...

I have to voice my passion for your kindness giving support to those people that should have guidance on this important matter.

salesforce admin training in bangalore

salesforce admin courses in bangalore

salesforce admin classes in bangalore

salesforce admin training institute in bangalore

salesforce admin course syllabus

best salesforce admin training

salesforce admin training centers

Customer relationship management said...

Excellent post for the people who really need information for this technology.

servicenow training in bangalore

servicenow courses in bangalore

servicenow classes in bangalore

servicenow training institute in bangalore

servicenow course syllabus

servicenow course syllabus

servicenow training centers

Customer relationship management said...

Very useful and information content has been shared out here, Thanks for sharing it.

cloud computing training in bangalore

cloud computing courses in bangalore

cloud computing classes in bangalore

cloud computing training institute in bangalore

cloud computing course syllabus

best cloud computing training

cloud computing training centers

Customer relationship management said...

Awesome post with lots of data and I have bookmarked this page for my reference. Share more ideas frequently.

dell boomi training in bangalore

dell boomi courses in bangalore

dell boomi classes in bangalore

dell boomi training institute in bangalore

dell boomi course syllabus

best dell boomi training

dell boomi training centers

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.

sap abap training in bangalore

sap abap courses in bangalore

sap abap classes in bangalore

sap abap course syllabus

best sap abap training

sap abap training center

sap abap training institute in bangalore

watson said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful

sap hana courses in bangalore

sap hana classes in bangalore

sap hana training institute in bangalore

sap hana course syllabus

best sap hana training

sap hana training centers

best sap hana training

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.

sap hr courses in bangalore

sap hr classes in bangalore

sap hr training institute in bangalore

sap hr course syllabus

best sap hr training

sap hr training centers

sap hr training in bangalore

watson said...

Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.

sap mm training in bangalore

sap mm courses in bangalore

sap mm classes in bangalore

sap mm training institute in bangalore

sap mm course syllabus

best sap mm training

sap mm training centers

watson said...

Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind

sap fico training in bangalore

sap fico courses in bangalore

sap fico classes in bangalore

sap fico training institute in bangalore

sap fico course syllabus

best sap fico training

sap fico training centers


meritstep1 said...

I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article. pega online training , best pega online training ,
top pega online training

Reshma said...


Get inspired by your blog. Keep doing like this....
German Classes in Chennai
German Classes in Bangalore
German Classes in Coimbatore
German Classes in Madurai
German Language Course in Hyderabad
German Language Course in Chennai
German language course in bangalore
German language course in coimbatore
Selenium Training in Bangalore
Software Testing Course in Bangalore

best software training institutes in Bangalore said...

Thanks for your post.

linux training institutes in bangalore
aws training in Bangalore

best software training institutes in Bangalore
training institutes in Bangalore
full stack developer course
dot net course
Devops course in bangalore
azure training in Bangalore