Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / February 2006

Tip: Looking for answers? Try searching our database.

Problems with programatically switching views

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DGibson - 28 Feb 2006 20:20 GMT
I have a form that has two views for it, "Request view" and "Approval view".  
There are user roles set for each view.  I have an "Everyone" role with no
specification, and then an "Approver role" that has specific AD accounts
listed.  I want to programatically test if someone changes views to the
Approval view that isn't in the Approver role and kick them back to the
Request view.

The problem I'm having is that it seems that the OnSwitchView script is
firing when the form is first opened, and it causes an error "InfoPath cannot
execute any view-related object model calls.  The view is not ready."  This
error I'm thinking is caused because of multiple switchview calls occuring
when the form opens, but I don't know why they are firing.

Here is the script I have for testing:
function XDocument::OnSwitchView(eventObj)
{
    // Test for Approver role
    var strCurrentRole = XDocument.Role;
    var strCurrentView = XDocument.View.Name;
   
    XDocument.UI.Alert(strCurrentView + " " + strCurrentRole);
   
    if (strCurrentView = "Approval view")
    {
        if (strCurrentRole = "Everyone")
        {
            XDocument.UI.Alert(strCurrentView + " " + strCurrentRole);
            XDocument.View.SwitchView("Request view");
        }
    }
}

When the form loads, I get the initial alert of "Request view Everyone".  
Then the second alert will fire "Approval view Everyone".  Then I get the
error message.  The form view doesn't actually change, I just see the Request
view as expected, but something more seems to be happening behind the scenes?

Is the OnSwitchView function supposed to be processed when the form is
initially opened?  And is there another method I can use to prevent any users
from manually switching views?
Greg Collins [InfoPath MVP] - 28 Feb 2006 21:09 GMT
You can't do it that way. A big compaint of mine: InfoPath will NOT allow you to switch views while switching views. Seems dumb to me because I can think of many times I've wanted to be able to do that.

Anyway -- a workaround: Turn off the view switching in the menus (see View Properties), and then use buttons to switch the views. Use conditional formatting to disable the buttons when you don't want a particular use to switch the view.

Signature

Greg Collins [InfoPath MVP]
Visit http://www.InfoPathDev.com

I have a form that has two views for it, "Request view" and "Approval view".  
There are user roles set for each view.  I have an "Everyone" role with no
specification, and then an "Approver role" that has specific AD accounts
listed.  I want to programatically test if someone changes views to the
Approval view that isn't in the Approver role and kick them back to the
Request view.

The problem I'm having is that it seems that the OnSwitchView script is
firing when the form is first opened, and it causes an error "InfoPath cannot
execute any view-related object model calls.  The view is not ready."  This
error I'm thinking is caused because of multiple switchview calls occuring
when the form opens, but I don't know why they are firing.

Here is the script I have for testing:
function XDocument::OnSwitchView(eventObj)
{
// Test for Approver role
var strCurrentRole = XDocument.Role;
var strCurrentView = XDocument.View.Name;

XDocument.UI.Alert(strCurrentView + " " + strCurrentRole);

if (strCurrentView = "Approval view")
{
if (strCurrentRole = "Everyone")
{
XDocument.UI.Alert(strCurrentView + " " + strCurrentRole);
XDocument.View.SwitchView("Request view");
}
}
}

When the form loads, I get the initial alert of "Request view Everyone".  
Then the second alert will fire "Approval view Everyone".  Then I get the
error message.  The form view doesn't actually change, I just see the Request
view as expected, but something more seems to be happening behind the scenes?

Is the OnSwitchView function supposed to be processed when the form is
initially opened?  And is there another method I can use to prevent any users
from manually switching views?
DGibson - 28 Feb 2006 21:39 GMT
Ah ha!  I didn't see that option in the view properties before.  That's
exactly what I needed, rendering the script issue a moot point.

Thanks for the help Greg.

> You can't do it that way. A big compaint of mine: InfoPath will NOT allow you to switch views while switching views. Seems dumb to me because I can think of many times I've wanted to be able to do that.
>
[quoted text clipped - 40 lines]
> initially opened?  And is there another method I can use to prevent any users
> from manually switching views?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.