D
DGibson
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?
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?