Paul B said:
Hi
I am using infopath SP1. I have a tet field called "name" All i want to do
is get the user name of the current user into this text field. I am also
using Portal.
I have read a lot of posts and still have no idea how to do this. I really
dont want to have to install any more software as the form needs to be
accessed by a lot of users.
Thanks
You can use scripting - Environment.UserName will get you the account name.
However, that isn't necessarily the same as the user's name. If you actually
want their name, it does start to get harder. You've got at least two
choices:
1. Get the InfoPath form to query Active Directory so that it can extract
the user's name based on the account name you get from Environment.UserName.
2. Use a web service. The InfoPath form calls the web service which then
queries Active Directory and returns the information you want.
3. Use the web service in SharePoint Portal Server. SharePoint supports a
"GetUserProfileByName" web service. More details at
http://msdn.microsoft.com/library/en-us/spptsdk/html/mUserProfileServiceGetUserProfileByName.asp
The advantage of (1) is that all of the code is self-contained in the form.
The BIG disadvantage is that in order to make the queries to AD, you have to
make the form fully trusted which is a real pain, although it is not too bad
if you've got certificates and you can code-sign the form.
The advantage of (2) is that the InfoPath form runs normally and doesn't
need to be fully trusted. The disadvantage is that you've got to set up a
web server so that you can run the web service.
The advantage of (3) is that you don't need to write the web service but you
do need to have profiles set up in SharePoint Portal Server.
I can provide some code for (2) if needed.
--Philip