InfoPath form and User login - InfoPath Dev
in

InfoPath Dev

InfoPath form and User login

Last post 05-17-2007 02:16 PM by Clay Fox. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 05-16-2007 11:05 PM

    InfoPath form and User login

    I want to do this:

    I want to  create an InfoPath form that when it opened the first time (isNew=true) it will remember the user login (stored it in a field) and then when someone will try to open this form, it will check if is  the same user that opened it on the first time..... If not... I want to close the form or to switch to other view (I try yo do this from the OnLoad event but I cam't do this)

  • 05-16-2007 11:30 PM In reply to

    Re: InfoPath form and User login

    I have done this several times, screened the user and then switched to the appropriate view as the form opens, overriding the default view.  However I have always done this with the opening rules.  I seem to remember something about that the view cannot be switched in the onload event.  It has to happen after load, as the opening rules are being executed.
  • 05-17-2007 01:56 PM In reply to

    Re: InfoPath form and User login

    Hi Clay Fox. I will explain my problem exactly

     

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

  • 05-17-2007 02:16 PM In reply to

    Re: InfoPath form and User login

    Ok, I looked up the issue I had remembered with the onload event, you can't switch views. However the work around is to change the default view. Greg explains it here. http://www.infopathdev.com/blogs/greg/archive/2005/06/27/Switch-Views-During-the-OnLoad-Event.aspx

    For your second issue you might add this to your logic and look first if it is a new form and then if not check the allowform before setting the default view.

    Otherwise what I have done, is not use code and the onload event but instead done everything in the opening rules. I have used SharePoint or a datasource to get the username.  I have used existing data in the form to determine whether it is new or an existing form.

    Have fun.

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.