I have an InfoPath Form that contain field (on main Data Source) named "UserLogin".
On it's OnLoad event I do this code:
function XDocument::OnLoad(eventObj)
{
var objNetwork = new ActiveXObject("WScript.network");
var login=objNetwork.UserName ;
if(XDocument.IsNew)
{
XDocument.DOM.selectSingleNode("/my:myFields/my:UserLogin").text=login; // Set the current user login as the value of "UserLogin"
}
else // NOT NEW FORM
{
var existLogin=XDocument.DOM.selectSingleNode("/my:myFields/my:UserLogin").text;
if (existLogin != login)
{
//This is the problematic part !!!!!!!!!!!!!!!!!!!!!!!!!!
}
}
}
Explain: If the form is new form I update on the "UserLogin" field to be the value of the user login that open this form.
If the form is NOT NEW - I check if the current user that open the form, is the same user that open it on the first time!!!!!!
If not (the problematic part)..... I want to close the form or switch view but as I can see I cant do those operations on the OnLoad event!!!!!!
What can I do?
By the way I also try this: I add to my Data Source a boolean field called "AllowForm" (deafult value=True)
In me code - In the (the problematic part) I write this:
if (existLogin != login) { XDocument.DOM.selectSingleNode("/my:myFields/my:AllowForm").text=False; }
And the I go to Tools-> Form Options-> Open and Save -> Rules -> Add -> Set condition: "if AllowForm is equal to False" -> Add action -> Switch to "View 2"
It's not work because this open role happen before the OnLoad event so I AllowForm still =True!!!! and the action not operate!!!!
Any Ideas????