Data in a submitted form changes! - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Data in a submitted form changes!

Last post 07-31-2012 11:23 AM by bmanda. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 03-03-2011 06:50 AM

    Data in a submitted form changes!

    Hi all,

    Ok, we're nearly reaching the end of a form project...  however, we have a slight issue!

    Our form is used to submit Purchase Reqs.  So, end users initiate a new form (in Infopath 2010 client) and fill out the details.  At the top of the form we have some code which pulls back AD information (Name, Dept, E-mail address etc).

    The form submits to a library - all ok.

    However.....   when a different user (lets say me for example) opens the form that has been submitted to the library, it then populates MY Active Directory information at the top of the form, effectively replacing the details that were saved on the form by the original requester!

    My question - How can we ensure that the AD details that are put onto the form when it is submitted remain the same (i.e. are NOT replaced!) when the saved form is opened by a different user??

    We are wanting to use the AD details (email for example!) for workflow, so this really shouldn't change!

    Thank you for any help!! 

    Kind regards,

    James

    Filed under: , ,
  • 03-03-2011 08:25 AM In reply to

    Re: Data in a submitted form changes!

    Hi, how do you populate the value of Ad on your form ? If you use codes to set your field you can set a condition this.New (wich mean the form is open for the first time) to populate or not your field.

  • 03-03-2011 08:43 AM In reply to

    Re: Data in a submitted form changes!

    Hi JayBranch and welcome!

    You can make the fields or section read-only. Right click on the field or section and in the properties dialog you should have read-only as an option. After you do that, you may also want to disable Save so that the user can't save to local XML and edit in Notepad (not an issue if you are using Web browser forms).

     

    Patrick Halstead
    Project Manager at Qdabra
  • 03-03-2011 08:44 AM In reply to

    Re: Data in a submitted form changes!

    We use some VB code (On form load) which sets variables and then populates the boxes on the form with details from AD.

    I have attached the code for you to look at:

    Public Sub FormEvents_Loading(ByVal sender As Object, ByVal e As LoadingEventArgs)

     

     

    ' Get the user name of the current user.

    Dim userName As String = Me.Application.User.UserName

    ' Create variables to hold the values pulled from AD

    Dim Location As String = String.Empty

    Dim FirstName As String = String.Empty

    Dim LastName As String = String.Empty

    Dim Mail As String = String.Empty

    Dim Title As String = String.Empty

    Dim Phone As String = String.Empty

    Dim Department As String = String.Empty

    Dim Manager As String = String.Empty

    Dim ipPhone As String = String.EmptyDim Name As String = String.Empty

     

    ' Create a DirectorySearcher object using the user name as the search filter.

    Dim searcher As DirectorySearcher = New DirectorySearcher( _

    "(sAMAccountName=" + userName + ")")

    ' Search for the user

    Dim result As SearchResult = searcher.FindOne

    ' Create a DirectoryEntry object for this user

    Dim employee As DirectoryEntry = result.GetDirectoryEntry()

    ' Assign the specified properties to string variables.

     

    'FIRST NAME

    If (Not (employee.Properties("givenName").Value Is Nothing)) Then

    FirstName = employee.Properties("givenName").Value.ToString()

    End If

    'LAST NAME

    If (Not (employee.Properties("sn").Value Is Nothing)) Then

    LastName = employee.Properties("sn").Value.ToString()

    End If

    'EMAIL

    If (Not (employee.Properties("mail").Value Is Nothing)) Then

    Mail = employee.Properties("mail").Value.ToString()

    End If

    'LOCATION

    If (Not (employee.Properties("physicalDeliveryOfficeName").Value Is Nothing)) Then

    Location = employee.Properties("physicalDeliveryOfficeName").Value.ToString()

    End If

    'TITLE

    If (Not (employee.Properties("title").Value Is Nothing)) Then

    Title = employee.Properties("title").Value.ToString()

    End If

    'TEL

    If (Not (employee.Properties("telephoneNumber").Value Is Nothing)) Then

    Phone = employee.Properties("telephoneNumber").Value.ToString()

    End If

    'DEPT

    If (Not (employee.Properties("department").Value Is Nothing)) Then

    Department = employee.Properties("department").Value.ToString()

    End If

    'MANAGEREMAIL

    If (Not (employee.Properties("ipPhone").Value Is Nothing)) Then

    ipPhone = employee.Properties("ipPhone").Value.ToString()

    End If

    'MANAGER

    If (Not (employee.Properties("manager").Value Is Nothing)) Then

    Manager = employee.Properties("manager").Value.ToString()

    Manager = Manager.Substring(3, Manager.IndexOf(",") - 3)

    Else

    Manager = "NO MANAGER"

    End If

     

    'NAME

    If (Not (employee.Properties("cn").Value Is Nothing)) Then

    Name = employee.Properties("cn").Value.ToString()

    End If

     

    ' Create an XPathNavigator to traverse the form

    Dim xnMyForm As XPathNavigator = Me.CreateNavigator()

    Dim ns As XmlNamespaceManager = Me.NamespaceManager

    ' Set the fields in the form

    xnMyForm.SelectSingleNode("/my:myFields/my:FirstName", ns).SetValue(FirstName)

    xnMyForm.SelectSingleNode("/my:myFields/my:LastName", ns).SetValue(LastName)

    xnMyForm.SelectSingleNode("/my:myFields/my:Alias", ns).SetValue(userName)

    xnMyForm.SelectSingleNode("/my:myFields/my:Email", ns).SetValue(Mail)

    xnMyForm.SelectSingleNode("/my:myFields/my:Manager", ns).SetValue(Manager)

    xnMyForm.SelectSingleNode("/my:myFields/my:Name", ns).SetValue(Name)

    xnMyForm.SelectSingleNode("/my:myFields/my:Location", ns).SetValue(Location)

    xnMyForm.SelectSingleNode("/my:myFields/my:Title", ns).SetValue(Title)

    xnMyForm.SelectSingleNode("/my:myFields/my:TelephoneNumber", _

    ns).SetValue(Phone)

    xnMyForm.SelectSingleNode(
    "/my:myFields/my:Department", ns).SetValue(Department)xnMyForm.SelectSingleNode("/my:myFields/my:ipPhone", ns).SetValue(ipPhone)

     

     

    End Sub

     

     

  • 03-03-2011 08:48 AM In reply to

    Re: Data in a submitted form changes!

    Hi Patrick,

    Thanks for the reply.  I've set the fields to read only... but they still change when the form loads, even after it's been submitted to the library.

    The code we use to pull back the AD properties is in the 'form load' section (see above).

    Should I use some code at this point to say 'If code is in here, do not change it'...  (but obviously in a code manner!)  :)

     

    Regards

    James

  • 03-03-2011 11:32 AM In reply to

    Re: Data in a submitted form changes!

    Hi, you can do that or you can also use the XmlForm.New Property you can put " If (Me.New) Then" on th e beginning of your load form event and finish with "End If"


  • 03-04-2011 01:57 AM In reply to

    Re: Data in a submitted form changes!

    Hi. I have a similar problem to James, and the Potemkine's solution sounds perfect.

     I'm new to Infopath/Sharepoint and i'm looking for a book or website with programming syntax, can anyone recommend a good one?. I can do a bit of VBa, so I'm happy with programming logic but it's the basics of Infopath's syntax that i need to know more about.

    For instance I tried solving this problem with a hidden text field on the form that i would populate after the initial load, and then check the value at the beginning of the on-load event, but I couldn't find out how to read the value into a variable.

    I tried

    strNewForm = xnMyForm.SelectSingleNode("/my:myFields/my:NewForm”).text
  • 03-04-2011 05:14 AM In reply to

    Re: Data in a submitted form changes!

    Potemkine - you are a genius.

    This worked great, now the form loads with the right details and they don't change when the form is opened after submission.

    10 points to you!  :)

     

    James

  • 07-31-2012 11:23 AM In reply to

    Re: Data in a submitted form changes!

    Hi, I had the same issue, but I used the UserProfile.asmx web service and populated the Preferred name in the form and after submitting the form and when other user opens the form, the requestor name is changing to the current user. I tried to set rules to disable the filed and made it read only also but no use
Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.