Link to home
Start Free TrialLog in
Avatar of AnthonyKRo
AnthonyKRoFlag for United States of America

asked on

VB Code For InfoPath Form

Hello, I am an intern looking for a way to have a Infopath form hosted on a Sharepoint site manage who is allowed to see completed forms. The forms will be stored in a location with more secure permissions than the template. But I need a way for the individual who filled out the form to see his completed form in the event he/she needed to update it.

I am currently trying to use code in Infopath to find the current user and load said information from the site into the form. The whole idea behind this is to store information that is only visible, from user side, by the user who entered it to protect any sensitive data.

I'm not 100% positive on the code to find current user, and if I did would it be possible to use that variable field as a trigger for rules in the form.
Avatar of melli111
melli111
Flag of United States of America image

Hi, how I do this is I create a view in the sharepoint form library called "My Forms" or something like that.  Make it the default view.  Apply a filter of   "where created by is equal to [Me]".  Now for your other view with all of the forms you can click site actions > edit page > modify shared web part  and apply audience targeting to restrict this view to a specific group.
Oh also, on the part of how you want to store user information in the form you can use sharepoint's userprofileservice as a secondary data connection to get this information.  See this link here:

http://blogs.microsoft.co.il/blogs/itaysk/archive/2007/04/05/InfoPath-_2D00_-Get-the-current-user-without-writing-code.aspx

(no code required)
Avatar of AnthonyKRo

ASKER

Thank you,

I seem to be having a little trouble setting up the connection though, after entering the "http://ServerName/_vti_bin/UserProfileService.asmx" instead of continuing  to the next steps I recieve an error stating,
"InfoPath cannot find or cannot access the specified web service description."
Upon expanding the details,
"The site is not a valid XML file.
Not enough storage is available to process this command."
Ohhh, In your add data connection I think you selected XML file.... select "WebService" instead, then click next and enter the url
Using InfoPath 2010, after choosing to add a connection I am given choices between:

SOAP Web service
SharePoint library or list
Database(MS SQL Server only)
XML Document

I chose the web service and entered the  "http://ServerName/_vti_bin/UserProfileService.asmx" but still recieved error.
Interesting - I have seen this error where your webservice is running using the incorrect asp.net version.  You can check this by going to the server that hosts your sharepoint site > start > run > inetmgr > Expand websites, find your sharepoint site, then you should see the _vti_bin. Right click it and go to properties.  You can change the asp.net version in there to 2.0
I figured out what was wrong with the data connection, I believe due to the fact that the SharePoint site being used is a secure intranet site it was stopping the regular http. After changing it to "https://ServerName/_vti_bin/UserProfileService.asmx" it allowed me to setup the connection.

I set up a read only text box to display current user that I'm planning to use to set up rules to load any data for the form already stored in the database. Unfortunately after I setup the text box properties, according to the article you pointed me to, I received an error on preview.

"The SOAP response indicates that an error occurred on the server:

The User Profile Manager object could not be loaded. ---> Value cannot be null.
Parameter name: serverContext"

Could this be from running a preview out of InfoPath instead of uploading it to the site first?

I haven't seen this error before so I researched it.  Looks like you need to modify your Alternate Access Mappings in Central Admin (which makes complete sense to me).  

I gathered that from this post here:  http://www.codebureau.com/blog/2010/02/18/RetrievingUserInformationInInfoPathWithoutCodeOneSolutionToValueCannotBeNullParameterNameServerContext.aspx

Here's the Microsoft link on applying your Alternate Access Mappings:  http://technet.microsoft.com/en-us/library/cc263208(office.12).aspx
What would the fqdn of the https://servername/_vti_bin/UserProfileService.asmx be

not sure where to find this
That would be your https://  url for your site.  Most of the time they are something like this:

https://server.domain.com

(configure that url in the AAM)
Just clarifying we should be using the same server name as in the data connection.

So
https://sameserverasdataconnection.domainofhostsite.com
Yes, it should be that same server name
We added an internal url with the context: https://servername.domain.com , to the intranet zone seeing how it is an intranet site and are still recieving the error.

The form is uploaded but has not been approved to allow it to open in the browser could this be causing a problem. Or is there something else we need to do with the internal url.
That's possible - if it's not approved or doesn't have the appropriate trust level it will block out certain data connections
Hello, the guy who normally handles form approval and activation is out of town. We've managed to figure out how to get the form approved and uploaded but can't seem to get it to appear in the sight. Checking site collection features its reported as activated but is not appearing on the site.
ASKER CERTIFIED SOLUTION
Avatar of melli111
melli111
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Managed to fiugre out how to get the form to the right spot but upon moving it, it shows up as a word doc
Something is definitely not right there ----- how did you manage to get the form to the right spot (what were your steps)?
Was trying t ocopy the template into the site we wanted it to appear in, followed your instructions and got it to appear correctly. Thank You
Thank You for sticking with this post for so long. If I ever need infopath/sharepoint help your number 1 on my list.
Glad I could help  :)  Happy InfoPath-ing!