Creating a sign off button - InfoPath Dev
in

InfoPath Dev

Creating a sign off button

Last post 11-26-2008 12:07 AM by Anuma. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 11-19-2008 01:56 PM

    Creating a sign off button

    Hi all,

     I am creating an infopath 2007 form that my users will fill out and submit to a WSS 3.0 (not a MOSS portal site) site. The form will have a section for the user to click a button and sign off on the form. The functionality I am trying to accomplish is the following:

    1. Click on a button to sign off on the infopath form
    2. The button will add the users name (preferably first and last) into a text box
    3. The button will also add the current time into a text box
    4. The button will become disabled and the textboxes will be read-only.  

    I should also mentioned that I am creating a "managed code" form with Visual Studio 2005.

     My struggles have been:

    1. Getting the User Name to even display
    2. Understanding the life cycle of an infopath form.  
    Any help would be greatly appreciated, or some guidance as to whether or not what I am trying to accomplish can be pulled off in sharepoint.
  • 11-19-2008 10:05 PM In reply to

    Re: Creating a sign off button

    Hi,

    You can set username to textbox by using following code. Write this in button onclick event.

    SetNodeValue(“/my:myFields/my:field1”,System.Environment.UserName);

    Use conditional format on button so that if all the text boxes are not blank then disable button.

    Here field1 is textbox control.

    Hopes this helps.

     

    Rajitha
  • 11-19-2008 11:53 PM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: Creating a sign off button

    Hi,

    Double click on the button and click on "EditFormCode" button. Copy Paste the below code.

     XPathNavigator xn = this.MainDataSource.CreateNavigator();

    XPathNavigator xnDateTime = xn.SelectSingleNode("/my:myFields/my:field1", this.NamespaceManager);

    string currentDate = DateTime.Now.ToString("yy-mm-ddThh-mm-ss");

    xnDateTime.SetValue(currentDate);

    XPathNavigator xnUserName = xn.SelectSingleNode("/my:myFields/my:field2", this.NamespaceManager);string currentUser = System.Environment.UserName.ToString();

    xnUserName.SetValue(currentUser);

     

    Field1 ---> Datetime field

    Field2 ---> Username field.

     If you want to display the only time in the Datetime field, then use below code:

    string currentDate = DateTime.Now.ToString("hh:mm:ss");

     

    Anuma Chinthapalli /
    http://www.GGKTech.com
  • 11-20-2008 08:32 AM In reply to

    Re: Creating a sign off button

    Thank you Anuma for the code snippet to work with. When i add this code to my infopath .cs form i get Security Exceptions(System.Security.SecurityExceptions to be exact) thrown on the following lines:

    1.   XPathNavigator xnDateTime = xn.SelectSingleNode("/my:myFields/my:field1", this.NamespaceManager);
    2.   XPathNavigator xnUserName = xn.SelectSingleNode("/my:myFields/my:field2", this.NamespaceManager);

    Do I have to create a certificate for this source to run on my machine? From your experience what are we looking at for my users who use this infopath form? Is there a work around just so that I can test it? Is there an alternative solution for having to have a signed certificate for this form?

  • 11-26-2008 12:07 AM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: Creating a sign off button

    Are you using full trust form?

    This code is working for me in a normal form.

    Anuma Chinthapalli /
    http://www.GGKTech.com
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.