Switch view based on user login - InfoPath Dev Sign in | Join | Help in Views InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Views » Switch view based on user login Switch view based on user login Last post 10-29-2009 07:17 AM by warrtalon. 19 replies. Page 1 of 2 (20 items) 1 2 Next > Sort Posts: Oldest to newest Newest to oldest Previous Next 07-22-2009 01:32 PM gowtham Joined on 07-08-2009 Posts 46 Switch view based on user login Reply Contact There are two views in a browser enabled InfoPath form which is published to a SharePoint form library. These views should switch depending upon the user logged in. The second view includes some data from the first view along with some additional Fields. If the user with view1 logs in, fills the form and saves it to the document library, as soon as the user 2 logs in the document library and opens the same form, view 2 should be opened. 07-22-2009 06:10 PM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact You can do this with a Form Load rule. Just open Form Options from the tools menu, and in the Open and Save section, click the Rules... button. From there, you should be able to add the necessary logic to switch views accordingly. Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 07-22-2009 08:36 PM In reply to gowtham Joined on 07-08-2009 Posts 46 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact Hi Jimmy, Thanks for the reply. I did apply the rules and the view is switching according to the rules but the view is switching only when the user clicks NEW in form library. But the saved form is not opening depending upon the log in. If user1 fills the form and saves it, even if user2 logs in the form open in the user1 view. But I want it to be opened in user2 view along the data that is filled by user1(Ofcourse that is included in user2 view) when user2 logs in. But thats not happening here. 07-22-2009 08:48 PM In reply to warrtalon Joined on 12-14-2007 Denver, CO Posts 980 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact It should be happening unless you have an existing form that didn't change when you re-published the template. This concept is very simple and is something I use on just about every form I create. The only way it won't switch views on an already-submitted form is if you have a condition telling it to only switch in certain scenarios. If you have no conditions, then either you are using an existing form that isn't reflecting the newly-published changes, or your logic is incorrect somehow. 1) Tell us how you are recognizing the current user and how you are using that info to switch the views 2) Attach your XSN to show us directly. Clayton Cobb || SharePoint MVP || Clayton's SharePoint MadnessPlanet Technologies || Federal Partner of the Year (2005-2010) || SLG Partner of the Year (2010) 07-23-2009 08:58 AM In reply to gowtham Joined on 07-08-2009 Posts 46 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact We have used a "user" hidden field to get the current user into this field by using "userName()" function. And I'm getting the approver1 and approver2 from XML data source. <?xml version="1.0" encoding="utf-8"?> <users> <approver1>user1</approver1> <approver2>user2</approver2> </users> Rules applied in "open and save" Condition:user is equal to approver1 Rule1: switch to view : Aprover1 view Condition:user is equal to approver2 Rule2 switch to view : Aprover2view 07-23-2009 03:42 PM In reply to Patrick Halstead Joined on 08-08-2006 Posts 5,112 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact Wait, doesn't Active Directory require "DOMAIN\" to be prefixed for the user names? Patrick HalsteadProject Manager at Qdabra 07-23-2009 03:57 PM In reply to gowtham Joined on 07-08-2009 Posts 46 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact Hi Patrick Halstead,Thanks for the reply. I'm not using Active Directory users so I don't have the DOMAIN problem and thats the reason why the switching is working fine when the NEW form is created in the document library. But the problem is that its not working fine for a saved form ie., when user fills and saves the form to the document library and approver1 logs in the same old view that is saved by the user is being visible. Did you get what I'm saying? Filed under: Gowtham 07-23-2009 04:38 PM In reply to warrtalon Joined on 12-14-2007 Denver, CO Posts 980 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact Why using an XML source like that instead of a basic SharePoint contacts list? InfoPath – User Roles in Browser-Enabled Forms Using Contacts List Clayton Cobb || SharePoint MVP || Clayton's SharePoint MadnessPlanet Technologies || Federal Partner of the Year (2005-2010) || SLG Partner of the Year (2010) 07-23-2009 07:06 PM In reply to gowtham Joined on 07-08-2009 Posts 46 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact Hi Warrtalon, I don't have any reason for that I know its just one way and I'm going in that way. Do you think that is causing problem? Filed under: Gowtham 07-23-2009 07:22 PM In reply to warrtalon Joined on 12-14-2007 Denver, CO Posts 980 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact Probably not. Are you storing userName() in the hidden field using a default value or a rule? If you use a default value, then that value sets once and never changes. If you use a Form Open rule, then it sets the value for the current user each time it's opened. This is detailed in my blog above. Perhaps this is your issue? Clayton Cobb || SharePoint MVP || Clayton's SharePoint MadnessPlanet Technologies || Federal Partner of the Year (2005-2010) || SLG Partner of the Year (2010) 07-23-2009 07:42 PM In reply to gowtham Joined on 07-08-2009 Posts 46 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact Hi warrtalon,Thanks for the quick reply. That might be the reason. I'm using the default value. Can you tell me how to store userName() using rule? Filed under: Gowtham 07-23-2009 07:48 PM In reply to warrtalon Joined on 12-14-2007 Denver, CO Posts 980 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact Just like you're switching the view. Before switching the view, make this rule: Set a field's value user to userName() Then, switch view based on user. So simple you could kick yourself, yah? Hopefully, that's all it is. Clayton Cobb || SharePoint MVP || Clayton's SharePoint MadnessPlanet Technologies || Federal Partner of the Year (2005-2010) || SLG Partner of the Year (2010) 07-23-2009 07:54 PM In reply to gowtham Joined on 07-08-2009 Posts 46 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact This sounds more relevant. I will try this tomorrow and let you know.Thanks for the help. Filed under: Gowtham 07-23-2009 11:42 PM In reply to Patrick Halstead Joined on 08-08-2006 Posts 5,112 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact good idea from Clay, but you know relying on local machine usernames is just bad practice since it is not secure at all Patrick HalsteadProject Manager at Qdabra 07-24-2009 05:51 AM In reply to gowtham Joined on 07-08-2009 Posts 46 Re: Switch view based on user login Mark as Not AnswerMark as Answer... Reply Contact I don't have Active directory installed on that machine. I just practice on that machine. So security is not an issue. Thanks for the advice Patrick. I will keep that in mind. Filed under: Gowtham Page 1 of 2 (20 items) 1 2 Next > Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
There are two views in a browser enabled InfoPath form which is published to a SharePoint form library. These views should switch depending upon the user logged in. The second view includes some data from the first view along with some additional Fields. If the user with view1 logs in, fills the form and saves it to the document library, as soon as the user 2 logs in the document library and opens the same form, view 2 should be opened.
You can do this with a Form Load rule. Just open Form Options from the tools menu, and in the Open and Save section, click the Rules... button. From there, you should be able to add the necessary logic to switch views accordingly.
Hi Jimmy,
Thanks for the reply. I did apply the rules and the view is switching according to the rules but the view is switching only when the user clicks NEW in form library. But the saved form is not opening depending upon the log in. If user1 fills the form and saves it, even if user2 logs in the form open in the user1 view. But I want it to be opened in user2 view along the data that is filled by user1(Ofcourse that is included in user2 view) when user2 logs in. But thats not happening here.
It should be happening unless you have an existing form that didn't change when you re-published the template. This concept is very simple and is something I use on just about every form I create. The only way it won't switch views on an already-submitted form is if you have a condition telling it to only switch in certain scenarios. If you have no conditions, then either you are using an existing form that isn't reflecting the newly-published changes, or your logic is incorrect somehow.
1) Tell us how you are recognizing the current user and how you are using that info to switch the views
2) Attach your XSN to show us directly.
We have used a "user" hidden field to get the current user into this field by using "userName()" function.
And I'm getting the approver1 and approver2 from XML data source.
<?xml version="1.0" encoding="utf-8"?>
<users>
<approver1>user1</approver1>
<approver2>user2</approver2>
</users>
Rules applied in "open and save"
Condition:user is equal to approver1
Rule1: switch to view : Aprover1 view
Condition:user is equal to approver2
Rule2 switch to view : Aprover2view
Wait, doesn't Active Directory require "DOMAIN\" to be prefixed for the user names?
Hi Patrick Halstead,
Thanks for the reply. I'm not using Active Directory users so I don't have the DOMAIN problem and thats the reason why the switching is working fine when the NEW form is created in the document library. But the problem is that
its not working fine for a saved form ie., when user fills and saves the form to the document library and approver1 logs in the same old view that is saved by the user is being visible. Did you get what I'm saying?
Why using an XML source like that instead of a basic SharePoint contacts list?
InfoPath – User Roles in Browser-Enabled Forms Using Contacts List
Hi Warrtalon,
I don't have any reason for that I know its just one way and I'm going in that way. Do you think that is causing problem?
Probably not. Are you storing userName() in the hidden field using a default value or a rule? If you use a default value, then that value sets once and never changes. If you use a Form Open rule, then it sets the value for the current user each time it's opened. This is detailed in my blog above. Perhaps this is your issue?
Hi warrtalon,
Thanks for the quick reply. That might be the reason. I'm using the default value. Can you tell me how to store userName() using rule?
Just like you're switching the view. Before switching the view, make this rule:
Set a field's value user to userName()
Then, switch view based on user.
So simple you could kick yourself, yah? Hopefully, that's all it is.
This sounds more relevant. I will try this tomorrow and let you know.Thanks for the help.
good idea from Clay, but you know relying on local machine usernames is just bad practice since it is not secure at all
I don't have Active directory installed on that machine. I just practice on that machine. So security is not an issue. Thanks for the advice Patrick. I will keep that in mind.