Clayton's SharePoint Madness

All About SharePoint, InfoPath, and SharePoint Designer!

InfoPath – Get user information without writing code (extended)

Posted by Clayton Cobb on June 21, 2009

In terms of free, out-of-the-box functions, I consider the UserProfileService to be the most powerful thing that can be used in SharePoint-based InfoPath forms.  Itay Shakury made this wonderful blog post over two years ago that told us how to Get the current user without writing code.  That blog post is so popular that Itay is still answering questions as recently as TODAY (June 20th, 2009).  What we will talk about today is how to take this concept and extend it further so that you can get any profile info for any user by querying within the form after it has been opened through rules triggered by changed fields and buttons.  One specific example will be to use the Manager node to get the manager’s additional info.  Let’s begin…

Note: The following assumes you have already implemented the UserProfileService solution above, specifically the GetUserProfileByName method…

Another Note: The UserProfileService does NOT touch Active Directory.  It only touches the Profile Database, which is part of the SSP, so it requires you to be importing profiles through the SSP to populate this database, because that’s where all the information comes from.  The profile import pulls data from Active Directory, so it’s like connecting to AD, but not directly.  Therefore, this web service is only available through MOSS and not WSS 3.0.  For anyone who would like to do the same things but without having this web service, please consider using the Qdabra Active Directory Web Service that can be used in any type of InfoPath form as long as the organization uses Active Directory.

This write-up will be very involved, so in order to keep it from being 20 pages long, I’m going to explain certain concepts in detail ONCE, and then I will refer to that concept multiple times later without having to show more screenshots.  Hopefully, that works. The 4 main ways we will be using the UserProfile Service:

  1. Populating default information upon form load
  2. Populating queried information with a button
  3. Populating queried information with a dropdown tied to a secondary data connection
  4. Getting Manager info

These are the steps we’ll take:

  1. Create form template with all relevant data elements
  2. Create layout table showing data groupings
  3. Create form library
  4. Create UserName custom list
  5. Create Data Connections – GetUserProfileByName web service, AutoFilename library Submit, and UserName list Receive
  6. Configure all fields and buttons - default values and rules
  7. Test Functionality

Create form template with all relevant data elements

You won’t need all of these for every form, but they are elements that I use for achieving some of the concepts.  We’re combining all of the concepts, so you can either pick out what you need or build it all for practice, and then apply bits and pieces where applicable on your existing and future forms.  The element names should be self-explanatory, so I’ll just use a screenshot to show you what should be built in the main data source (Fig 1) 


Fig 1 – Form template showing all relevant data elements

Create layout table showing data groupings

In reality, you won’t end up showing most of these fields on the canvas of your forms, but they are showing here for testing and demonstration purposes.  I recommend hiding most of the fields like the ones showing usernames and instead showing meaningful ones like the name fields.  Again, the picture should be self-explanatory up front, so just follow this structure (Fig 2).  Add a row for that custom button, then just drag the button to the canvas and rename it.  We will configure it later.  Also, do the same for the Submit and Close (optional) buttons below the table.

 

Fig 2 – Creating the layout table

Create form library

Create a basic Form Library on your SharePoint site.  Go to Form Settings > Library Settings > Advance Settings > Display as Web Page (optional).

Create UserName custom list

Create a Custom List on your SharePoint Site.  Change the Title column to UserName, and create another column named FullName.  Populate this list with 3 known users (Fig 3) and be sure to use their exact username (i.e. ccobb) and not the domain name (i.e. domain\ccobb).  For the Full Name, put whatever you prefer to use as a friendly name for that user.


Fig 3 – Creating the custom UserName list

Create Data Connections – GetUserProfileByName web service, AutoFilename library Submit, and UserName list Receive

Create 3 data connections (Fig 4) starting with the GetUserProfileByName web method from the first part of Itay’s blog entry

 

Fig 4 – List of all Data Connections needed

Next, create the Submit data connection for submitting the form to your form library while using the strFilename data element (Fig 5).  Ensure you select “Allow overwrite if file exists.”

Fig 5 – Submit using strFilename

Lastly, create a Receive data connection for retrieving the list of pre-defined usernames and full names.  Be sure to select those two nodes when connecting to the list (Fig 6)


Fig 6 – Retrieve UserName and FullName from custom list

Configure all fields and buttons – default values and rules 

There is a lot of work to do here, so bear with me.  I’ll try to consolidate the similar settings to hopefully make it quicker to read and do. We have logic built in 5 places (not including the Submit and Close buttons):

  1. strSubmitter – Default value and rules for setting other field values
  2. strSubmitterMgr – Queries web service and a rule for setting other field values
  3. Form Load – A rule for setting field values
  4. btnCurrentMgrInfo – A rule for setting other field values
  5. strSelectedUser – Bound to secondary data connection as a dropdown list, multiple web service queries, and actions for setting other field values.  This field puts it all together into one action.

strSubmitter – Set the default value for this data element to the function userName() (Fig 7).


Fig 7 – Setting strSubmitter default value to userName()

Create a rule with 3 actions that sets the values of the other 3 submitter fields (Fig 8).  Each action starts with “Set a field’s value,” but I have scrolled right to show the formulas.  Each formula is from the 2nd half of Itay’s blog entry.  I will show how to do the strSubmitterMgr rule as one example to follow for all three (Fig 9).  The actions HAVE to be in this order, or at least make sure that strSubmitterMgr is last in line.  Due to there being no conditions, this rule fires as soon as strSubmitter is populated by the userName() default value.

 

Fig 8 – Create a rule with 3 actions for strSubmitter

The formula for strSubmitterMgr is substring-after(Value[Name = "Manager"], “\”).  The Xpath for that statement in my form is substring-after(xdXDocument:GetDOM(“GetUserProfileByName”)/dfs:myFields/dfs:dataFields/s0:GetUserProfileByNameResponse/s0:GetUserProfileByNameResult/s0:PropertyData/s0:Values/s0:ValueData/s0:Value[../../../s0:Name = "Manager"], “\”).  I chose this for the example, because it is the most complicated.  It is using the substring-after function to strip out all the data that comes after the backslash, because the value that returns for “Manager” is a full domain name (i.e. domain\ccobb).  We only want the username (i.e. ccobb), thus the substring-after function.  If you built your form exactly like mine, then you can click the Edit Xpath button and paste in the Xpath statement above.  However, that would not teach you how to use the GUI to achieve this goal, and your forms won’t always follow this format, so this is how you create that formula (Fig 9).

  1. Set the Action to “Set a field’s value.” Select strSubmitterMgr in the Field box.  In the Value box, click the function button (fx). In the Formula box, type substring-after(, “\”) – copy and paste if you’d like.  Then, put your cursor before the comma and click Insert Field or Group.
  2. In Data Source, select GetUserProfileByName (secondary).  Drill all the way down through the dataFields groups until you get to the Value node.  Select the Value node, then click Filter Data.
  3. Click Add
  4. In the first dropdown, click select field or group.  From there, do the same thing you did in step 3 above.  Get back to the GetUserProfileByName data source and drill down until you see the Name node.  Select that node, set the operand to is equal to, then set the last pulldown to the text of “Manager”

If done properly, then all of those boxes should look like Figure 9.  Follow the same procedure for the other two fields in Figure 8 except for the substring-after function.  Hint: at the Insert Formula screen, you can copy that statement and paste it in the same box when configuring other fields.  You can then double click the Value[Name = "Manager"] part that is underlined and click through the settings to change the Name part of step 5.

 

Fig 9 – Creating the strSubmitterMgr formula to retrieve just the Manager’s username

strSubmitterMgr – As soon as the 3rd action from above completes for populating strSubmitterMgr, it is time to fire off another rule with 4 actions (Fig 10).  The first 2 actions have to be in that order, and they have to be first.  The last 2 actions are interchangeable.  Be sure to place these rules on the strSubmitterMgr field and not the strSubmitter field!

Fig 10 – Create a rule with 4 actions for strSubmitterMgr

You already know how to do the last two actions, because they are exactly the same as the strSubmitter actions.  Just be sure to remember and set the field values for strSubmitterMgrEmail and strSubmitterMgrName.  We’ll now focus on the first two actions.  The Query using a data connection: GetUserProfileByName is extremely simple.  You just click Add Action and choose Query using a data connection in the Action pulldown.  It then gives you another pulldown of data connections where you choose GetUserProfileByName.  That’s it.

The first rule requires some direct attention, because it is where the magic happens for this entire blog entry.  It looks simple and actually is simple, but it’s the part that people never think of or just don’t realize it can be done.  All we are doing is setting the AccountName field to the current field’s data.  Ok, so what is this AccountName field?  We never created such a thing!  Ah, well it’s the only node in the queryFields group of the GetUserProfileByName data connection.  We are taking the Manager’s username from strSubmitterMgr and sending it to this field just before querying that web service.  This sends the Manager’s username to the web service so that it will return the data set of profile information relevant to the Manager instead of the Submitter.  This is the key to getting information other than the current user’s!

Here’s how you do it (Fig 11).  Click Add Action.  In the Action pulldown, select Set a field’s value; in Value, select strSubmitterMgr (should show a dot afterwards); in Field, click the Select a Field or Group button.  In Data Source, choose GetUserProfileByName (secondary), then drill down through the queryFields nodes until you reach the AccountName node.  Select it and click OK.  Pretty simple, huh?

 

Fig 11 – Sending a new query value to the GetUserProfileByName web service

Form Load – For the form’s Open Behavior, you will set a rule with 8 actions, all of which you have done already in this blog entry (Fig 12).  Here is a quick list of the actions and their formulas

  1. strCurrentUser – Set field’s value to userName()
  2. AccountName - Set fields value to strCurrentUser
  3. Query GetUserProfileByName
  4. strCurrentUserEmail – Set field’s value to Value[Name = "WorkEmail"]
  5. strCurrentUserName – Set field’s value to Value[Name = "PreferredName"]
  6. strCurrentUserMgr – Set field’s value to substring-after(Value[Name = "Manager"], “\”)
  7. strCurrentUserMgrEmail – Set field’s value to NULL
  8. strCurrentUserMgrName – Set field’s value to NULL (setting these to NULL so that btnCurrentMgrInfo works properly without keeping saved data in these fields when re-opening)

These steps are sending the current user’s username to the GetUserProfileByName web service, which returns a data set of profile info that is used to populate three other fields of information about the current user – WorkEmail, PreferredName, and Manager.  This may be the same info as the submitter, but it can accommodate users other than the submitter.

 

Fig 12 – One rule with 12 actions to perform each time the form opens

The reason why we’re using the a default value on strSubmitter and a rule for strCurrentUser is because using a default value makes the data populate once and stay the same during subsequent edits.  Since our current user may not be the same as the submitter, we must use a rule when the form opens to set strCurrentUser to the current user’s username while the strSubmitter field will always have the original submitter’s username.  All of the Submitter fields populated above will remain static, because there is always only one submitter.  The CurrentUser fields will always be dynamic depending on who opens the form.

btnCurrentMgrInfo – This is the button labeled Get Current Manager Info.  This button will have one rule with 4 actions that are identical to the strSubmitterMgr rule above except that the data will be sent to different fields (Fig 13).  You start by setting the AccountName of the GetUserProfileByName web service to the username of the current user’s Manager.  You then query the web service with the Manager’s username, which returns a data set of profile information about the current user’s Manager.  You then set the current user manager fields to their respective values of WorkEmail and PreferredName.  This example is just illustrating how you can use a button to populate such info.


Fig 13 – One rule with 4 actions to perform on a button push

strSelectedUser – This example puts a lot of concepts together into one simple action of choosing a dropdown selection.  You start by changing your strSelectedUser control to a dropdown box (the field next to Choose User).  You then configure the dropdown to pull data from the UserNames list (Fig 14).  First, you choose the radio button for Look up Values from an External Data Source.  In the Data Souce, choose UserNames.  In Entries, click the button and select the UserNames repeating group, then click Ok.  For Value, choose the UserName node, and for Display Name, choose the FullName node.  What this is going to do is show the user some friendly Full Names, but the values behind those selections will be actual User Names.


Fig 14 – Configuring strSelectedUser as a dropdown bound to the UserNames list

Next, create one rule on strSelectedUser with 5 actions (Fig 15).  Again, these actions are now familiar, but we’re combining multiple steps into one rule and using one new concept.  We first set the web service’s AccountName node to the value of strSelectedUser, which if you recall is the actual User Name of the name chosen in the pulldown.  Next, we query the web service.  Then, we take the User Name of the Manager of the person selected and set the web service’s AccountName to this value.  Basically, we’ve iterated through the earlier processes in this blog entry without using separate data fields.  We now have yet another data set of profile info, which allows us to do the last step.  The last step is to set strSelectedUserMgr to the Full Name (FirstName concatenated with LastName) of the selected user’s Manager.  So think about it, we started with a user selected in a pulldown and jumped all the way to that user’s manager’s friendly Full Name all in one simple click.

For the 3rd action, remember to use this formula to get the Manager’s username: substring-after(Value[Name = "Manager"], “\”).  On the 5th step, use this new formula for concatenating the FirstName with the LastName (these are attributes from the web service): concat(Value[Name = "FirstName"], ” “, Value[Name = "LastName"]).

 

Fig 15 – Creating one rule with 5 actions on the strSelectedUser pulldown

The custom Submit button is optional, but if you’d like to use that concept, please use my other write-up on that topic: Auto-Generating Filenames for InfoPath Forms.

Test Functionality

Publish the form, go to the form library, then click New.  In my example, I’m logged into the browser with an account named SharePoint Tester, and I am its manager.  The form should be completely populated in the Submitter section, and it should be partially completed in the CurrentUser section.  Notice the info is the same due to the fact that you are the submitter AND the current user, since you created this form as new.  The Current User Manager info is not populated, because we have to push the button to populate it.  The Selected User section is blank, because we have select a user from the pulldown first (Fig 16).


Fig 16 – Testing a new form

Submit your form, then re-open it with a different user account.  In my example, I started with a tester account and then logged in as myself to view the submitted form.  Notice that the Submitter information hasn’t changed, but the CurrentUser info now reflects the new user’s info, including that user’s manager’s username.  Click on the Get Current Manager Info button and watch the next two fields get populated with the Current User’s Manager’s information (Fig 17).

 

Fig 17 – Current User info is dynamic and a button can be used to retrieve user profile info

For the last test, we will make a selection in the Choose User pulldown and see what happens.  Choose one of the names in your pulldown and see if it populates the Selected User Manager field with that person’s manager’s full name (Fig 18).

 

Fig 18 – Use the value from a pulldown to determine that user’s manager’s Full Name

85 Responses to “InfoPath – Get user information without writing code (extended)”

  1. [...] Go here to see the original: InfoPath – Get the current user without writing code (extended) [...]

  2. M. Masterson said

    You are AWESOME! Thanks for putting this together. I now understand what you meant in your InfoPathDev.com reply. My problem was trying to set/change the AccountName parameter of the UserProfileService web service.

  3. Larry W. Virden said

    Thank you so much for such a detailed blog!

    Early in the blog, you say:
    I recommend hiding most of the fields like the ones showing usernames and …

    How do you recommend hiding of the fields?
    Removal of the controls containing the information just makes future use of the fields more difficult, doesn’t it? I thought about using the conditional formatting option of hiding the control, but that requires a condition and I’m uncertain how best to define that condition.

    I can certainly see how, if there were a way to do it, conditionally hiding the info, then allowing a maintenance person the means of indicating “now, display all the fields” would make debugging a form much easier…

    • Clayton Cobb said

      Larry, by “hiding,” I just mean to not put those on the canvas. All of these are administrative fields that wouldn’t normally be shown on the canvas, but I put them there for testing. If you end up having a bunch, and you think the form will need to be debugged a lot, then you could create a boolean field with a checkbox that only displays to a certain user or group of users. If that box gets checked, then all the administrative fields can show up for debugging. This would require all those fields to be on the canvas and hidden via conditional formatting that says if the Admin checkbox is FALSE, then hide. Or, you could create an entirely separate view showing all these controls and make that view not show up in the Views dropdown. When testing in preview mode, the form admin could switch to that view in the toolbar and debug it. There are many ways to go about doing this and all should be simple.

  4. Larry W. Virden said

    Clayton, I have been thinking about doing something like this (hiding administrative fields conditionally) for the past few days on a form that I’m building. I have several controls whose fields are used as “working data variables” which don’t need (and in some cases should not be) displayed to the normal user.

    I have been trying to figure out how to implement the admin checkbox so that admins can access it to turn it on or off, but the average user wouldn’t see it or be able to modify it. I’m not certain how to set things up so that most people don’t see something, but certain people, or even better people in a certain distribution list, sharepoint list, or sharepoint group DO get to see it.

    Do you know of any articles that cover that sort of topic?

    Thank you so much for taking the time to answer my questions.

    • Clayton Cobb said

      Larry, as an addition/revision to my User Roles article, I have a new method for more easily restricting portions of the form based on a person’s group membership by using GetCommonMemberships. A colleague at work was fumbling around with the idea and thought it would make sense to try that method. ‘Lo and behold, it works wonderfully, so I’m going to amend that article. However, remember that this idea is only necessary for browser-enabled forms. For rich client forms, you can simply use the User Roles function that you find in the Tools menu. It works like a charm.

  5. Clayton Cobb said

    Larry, did you read my User Roles post? http://claytoncobb.wordpress.com/2009/06/14/user-roles-in-browser-enabled-forms/. This is only necessary in browser-enabled forms. If you are using Rich Client, then simply use the User Role function to specify a group of people who can see a certain control. Or, use roles to determine who can go to a special admin view.

  6. Very good post Clayton. Exactly what I need because, like you, I am also a non-developer MOSS consultant. Doing everything without writing code is preferred.

  7. Larry W. Virden said

    Clayton, I have read that article, though I don’t understand it all yet.

    I am writing browser enabled forms, so your instructions are relevant. And I’m using InfoPath 2007. However, I don’t have access to Outlook 2007 at this time, so I’m uncertain how much of the instructions will work in this environment – for instance, the contact list steps don’t seem to work here.

    I understand the use of the GetProfileByName for the current user ; I’ve done that a few times so far.

    Thank you so much for all your suggestions!

    • Clayton Cobb said

      Larry, you are using InfoPath 2007, but your org doesn’t use Office 2007 as a whole? InfoPath is part of the Office 2007 suite along with Outlook. How does that work? Anyway, the change I’m going to make to the User Roles thread will no longer use a contact list and will use another web method from this same UserProfileService. It will allow you to check all the group memberships of a user without code – both AD and SharePoint groups.

      • M. Masterson said

        I look forward toi reading this and implementing it to control what the users are able to see on a form.

  8. Larry W. Virden said

    Sometimes the life of a developer has more twists than a maze in a Zork adventure. Yes, in my environment, I am using InfoPath 2007, but MS Office 2003. InfoPath 2007 forms published to our sharepoint work fine.

    I too will be interested to read your updated article. Thank you so much for your contributions!

    • Clayton Cobb said

      Larry (and others), I plan to do this very soon (maybe even tonight), but in case you need the solution quickly, I can point you in the right direction. If you use the concepts I’ve written in this article, then you might be able to get it to work. Here are the quick hits:
      - Make another DC to the UserProfileService, but this time choose the GetCommonMemberships method (notice it accepts the same parameter as GetUserProfileByName, which is the AccountName value that we know as the username)
      - Upon form load, the current user’s info gets sent to the DC, which returns all the information about that user’s group memberships – both AD _and_ SharePoint
      - Determine which of the fields is UNIQUE in your organization and that can be used easily in sending emails. The one I plan to use is the DisplayName node, because it’s a friendly name and can resolve to an email address directly within Outlook
      - When putting your conditional formatting on sections (or any control), check to see if the current user is a member of a group name you specify. Point to the DisplayName node, and choose “all occurrences of DisplayName are not equal to ‘group text’”

  9. maleesha said

    You are a superstar! Thanks for the great information. I don’t know what I would do without this blog. I would be a SharePoint rock. Everyone who even CARES about SharePoint needs to set this as their HOME PAGE.

  10. Larry W. Virden said

    Good afternoon, sir.
    I was trying to code up your example, and ran into a peculiar snag. At Figure 10, when I was creating the “magic”, I found that my “set a field’s value” didn’t turn out to look like yours. My action says
    Set a field’s value: AccountName = strSubmitterMgr
    whereas your action says
    Set a field’s value: AccountName = .

    I followed your instructions exactly, even deleting the rule a couple times to make certain that I filled in the fields in the same order as you. It just isn’t turning into a . so I was wondering if you had any ideas on what I might be missing.

    • Clayton Cobb said

      Larry, did you try to set that rule on strSubmitter or strSubmitterMgr? Since by that point in the blog, I’m trying to cut out extra typing, I didn’t exactly specify that you need to put that ruleset on the strSubmitterMgr field, not the strSubmitter field from the previous step. the “.” shows up when a field is referencing itself. It shows the full name of the field when you reference a field other than the one you’re modifying. That tells me you are likely adding it to strSubmitter.

  11. Larry W. Virden said

    Clayton, the issue that confused me was where the rule was to go. Right before you discuss the SetSubmitterMgrInfo rules, you were talking about the SetSubmitterValues rules. So unfortunately I just attempted to add the SetSubmitterMgrInfo rules into the same text field.

    Sometimes I am too literal for my own good.

  12. Larry W. Virden said

    At figure 14, I think you might want to mention that in the drop-down list box properties, the user needs to select “look up values from an external data source” radio button.

    • Clayton Cobb said

      Larry, thanks for the feedback. I added that step where it belongs, and I also added a note about the strSubmitterMgr rule set so that people don’t get confused.

  13. Larry W. Virden said

    Well, one last note. Thank you so much for your patience. I was able to muddle through and get the example set up – turns out that the manager information is not available at the site where I was setting things up, so while it gave me a lot of good practice thinking about making use of infopath and web services, ultimately other factors prevent me from achieving my goal.

    However, your examples are really appreciated, and I hope you continue the excellent work.

    • Clayton Cobb said

      Larry, that’s a shame to go through all this work and not have the Manager attribute available. Does your organization not populate that value in Active Directory, or is it just empty in SharePoint? If AD has it, we can get it into the Profile Database easily, which then makes it available to the web service we’re using. You wouldn’t be able to achieve your goal relative to getting the manager if they don’t have managers assigned in AD. The only way would be to create a database (SharePoint List, Access, Excel, SQL) that associates usernames with Manager usernames. You could then still use the web service to get Manager info as long as you knew which usernames matched with which Managers.

  14. Larry W. Virden said

    While I am not certain, I believe the issue is probably the information is not in Active Directory. Right now, I’ll not burn the resources to create a new list, in hopes that other work expected to occur this summer might result in a change in the situation.

    Thank you again for all your comments!

  15. Alana said

    Hi Clayton,
    Excellent post. Thank you so much for making my day!!

    • Clayton Cobb said

      Alana, glad to help and thanks for the kind remarks. If you have time to share your story, I’d love to hear how this helped to “make your day.” Thanks!

  16. [...] # InfoPath – Get the current user without writing code (extended) « Clayton's SharePoint Madness Sunday, June 21, 2009 9:13 AM by InfoPath – Get the current user without writing code (extended) « Clayton's SharePo… [...]

  17. WK said

    can anyone help? this dreadless error 5566, from sharepoint log

    Warning The following query failed: GetUserProfileByName (User: DEMO3\Administrator, Form Name: temp7, IP: , Request: http://demo3:8000/_layouts/FormServer.aspx?XsnLocation=http://demo3:8000/temp7/Forms/template.xsn&SaveLocation=http://demo3:8000/temp7&Source=http://demo3:8000/temp7/Forms/AllItems.aspx&DefaultItemOpen=1, Form ID: urn:schemas-microsoft-com:office:infopath:temp7:-myXSD-2009-07-17T02-13-47, Type: DataAdapterException, Exception Message: The remote server returned an error: (500) Internal Server Error. Server was unable to process request. —> Attempted to perform an unauthorized operation. The remote server returned an error: (500) Internal Server Error.)

    so far already tried,
    -disable anonymous access (IIS)
    -DisableLoopbackCheck

    fyi, i’m trying on a VPC

    • Clayton Cobb said

      WK,
      - Is DEMO3\Administrator a local built-in admin account and not an AD account? You need to use a domain account that is in your profile import – a real user
      - If this is a VPC without an SSP that has the profile import, then the web service is not available
      - If your farm is normal, then take your UserProfileService URL and place it in a browser. Does it work? Do you get a page with the list of web methods?
      - Do you have a root site collection built at the root of your web app?
      - In your SSP Admin > Personalization Services Permissions, are Personal Features turned on? Does your user account have that permission? It is required.

      • WK said

        Clayton, Thanks for your input,
        - DEMO3\Administrator is a local built-in admin account on workgroup
        - the UserProfileService url is working ok, i see the page with list of web methods
        - personal features has been turned on for DEMO3\Administrator

        Don’t quite understand on this, Do you have a root site collection built at the root of your web app? how can I check?

      • Clayton Cobb said

        WK, your web app is named demo3:8000, and I see you are doing this on a site named temp7 underneath that web app, so the URL is this: http://demo3:8000/temp7. Do you have a site collection built at the root of http://demo3:8000? Can you browse straight to http://demo3:8000?

        Anyway, please try to use a regular user account. Create one in your workgroup, add it to SharePoint as a user, import its profile, and then log in to the machine as that account so that you can utilize the web service. It isn’t meant to work with a built-in local admin account.

  18. Srinivas Madabushi said

    Great post ..
    Really helped me to push my project over the fence..
    Looking forward for some more great ones.

  19. WK said

    Clayton,

    Finally I get the form to work on browser on test server but not on VPC.
    Thanks for your help.

    To others who faced ‘An error occurred when accessing a data source’,
    -Make sure you uncheck anonymous access on IIS
    -Make sure you turn on Personal Features for user
    -Convert (external) data connections into UDCX file
    -If you connect to SQL, and your browser enabled form is not working with Windows credentials, try using SQL credentials

    • Hi Clayton and WK,

      I am getting this 5566 error when testing a browser-enabled form. This form is used in a SP extranet environment, so I can’t uncheck anonymous access on IIS right? When you say to uncheck anonymous access on IIS, are you talking about the setting in SP’s Central Administration? or a setting in IIS manager on the server? I’m not clear if these are the same settings or not, obviously…

      When I disable the form for the browser, and just open the form in the IP client, the web service works great and pulls in the current user name that I need.

      I was wondering if I needed to convert my secondary data connection (for the web service) into a UDCX file… so I will try that next since you mentioned it too.

      • Clayton Cobb said

        David, it is one in the same. If you change it in CA, then it changes it in IIS. Basically, the web application level setting for Anonymous Access must be turned off. After changing it in CA under Authentication Providers, you should go check the relevant IIS App Pool to ensure that it’s also turned off there.

      • Okay, thanks Clayton. I have double-checked CA and anonymous access is unchecked. (I was wrong, this form is not on our extranet server so I don’t have to leave anonymous access on). I have also converted the secondary data connection to a udcx file and republished the form.

        However, I still get the same 5566 error. Are there any other settings I should change that you know about?

        Thanks again!

        David

  20. Ben said

    Hi Clayton,

    Thanks for the fantastic post, I can really see a lot of great uses for it and it will certainly help improve/tidy up a load of forms I’ve created. I do have a question though that I haven’t been able to find a solution for as of yet and am hoping you can offer some insight?

    I am creating a form in which I would like to use similar functionality to the UserProfile web service, the difference being that rather than having a text box auto-populate with the current user’s name I would like to create a drop-down list that looks up all users within Sharepoint. You did something similar in this post by creating a list of usernames and Full Names but I’m hoping to avoid having to create a new list (which will have to be updated for new staff/leavers etc) when all the information I require is within Sharepoint.

    Let me know if I can provide any more info or detail but I would really appreciate any insight you have.

    • Clayton Cobb said

      Ben, you’re welcome. As for your request, there are a few options that may or may not work for you.

      1) SharePoint has a table in the database with users in it, and this table is exposed through a list called the User Information List. If you go to the top level of your site collection, click People and Groups > All People, you will this list (also Site Actions > Site Settings > Advanced Permissions > All People). From within InfoPath, you can simply create a Receive data connection, point it to the top-level site of your site collection, and choose the User Information List. You can even change the view settings of the list to get other info than what is seen by default, and you can use the OWSSVR.DLL method to view the list as XML and consume it in InfoPath as an XML DC. There are two gotchas, though. This list does _not_ auto-populate itself with all users in AD. It only puts a user in there whenever a user is given permissions directly in SharePoint (i.e. not through a security group, but as an individual) or is resolved in a People Picker (i.e. Person/Group field), so there is the chance that your UIL won’t be 100% complete. Also, when it’s a ton of users, it _will_ severely affect the loading performance of your for (or whenever you choose to pull that info down). It’s better to pre-filter the data and only receive a relevant subset unless you have a small # of users.

      2) Use Qdabra’s Active Directory Web Service, which is very similar to the User Profile Service, but it actually touches AD directly instead of relying on the SharePoint profile database. It does not require MOSS or SharePoint at all and has more capabilities/features than the User Profile Service, such as the ability to enumerate all users. It is a cheap web service that doesn’t require putting code in your form.

  21. Bharath said

    Clayton, you are doing a wonderful job when it comes to Infopath and it was you who inspired me poking and tweaking around Infopath and sharepoint.

    Sometime back i just found a way to pull out all the information of the user just with a contact list and a button.

    I recieve data from the “User Information List” which is on the site collection or web-app

    http://sharepoint/ or http://sharepoint//

    and i match the AccountId and the account field in that list in just a click of the button it populates all the fields on text boxes…

    Hope it helps

    • Bharath said

      I guess i repeated the same.. lol didn’t see it..

      • Clayton Cobb said

        Repeated the same? I basically do all of that, but I don’t use the UIL, because it is not a comprehensive list of all users. You should use the UserProfileService like I’ve shown, because that has EVERY user that has been imported from AD. The UIL only has users who have been individually added to a site or to a People Picker field, which isn’t usually half the organization.

  22. Kerrie said

    Hi Clayton,

    Between the posts that both you and Itay have put together I thought I had all of my problems solved. I need to do a number of things on my form.

    1. Automatically retrieve the user details, which I have successfully achieved via GetUserProfileByName
    2. Automatically retrieve the manager details, , which I have also successfully achieved via GetCommonManager

    Previously in AD I have created a distribution group called ‘Approvers’ of which my manager is a member. Because I know the name of my manger is it possible to find out if my manager is a member of the Approvers group?

  23. Thanh-Nu said

    Hi Clayton,
    Thank you for your post, I have followed your instruction and get most I need. I have to keep track of the submitter, current user, and querry the Manager phone, and email, exactly like you explained. I have no problem using GetUserProfileByName to retrieve the current user as default value for the submitter, and all related information. However, if I tried to use rules or explicit button to querry GetUserProfileByName again (by assign AccountName as you explained), I got “An error occurred when accessing a data source”. It looks like GetUserProfileByName just work the first time as the form is opened and if I explicitly querry it again with another value for AccountName, I got this error. Before assigning the new value to AccountName, I did display it in another field to make sure that the value is correct. But somehow, I cannot call GetUserProfileByName at more than one occurence in the form.
    Do you have any idea what I did wrong? When I create the secondary data source to querry GetUserProfileByName, I did check ‘Automatically retrieve data when form is opened’, because I think this is necessary to fill in the curent user information. Should I uncheck this option?
    Thank you in advance for your help.

    • Clayton Cobb said

      Thanh-Nu, I can’t tell what your culprit is from the explanation, but I can assure you of a few things:
      - You _definitely_ can send another query value to the GetUserProfileByName method with a rule (button or other control).
      - It’s definitely ok to have that box checked, and that only has to do with initial form load. This would not affect you sending a new value to the same web method while using the form
      - Make sure that the value you’re sending is just the username and not the full domain name. For example, “ccobb” is good, but not necessarily “domain\ccobb.” When you open the form, it sends just the username as the query value, and it’s the username of your Windows login, not your SharePoint web page login

      • Thanh-Nu said

        Thanks for your quick answer. Yes, I have tried on another example where I have a button to explicitly querry with GetUserProfileByName the way you did, and it works perfectly. I have to go back to the other case and track down the devil. I use Contact selector to select the user, then I select the field “AccountId”, and did make sure to take only the pattern after “\”, display it in another field to make sure it is a valid name, then querry with AccountName parameter.
        The steps and data obtained look logic to me, but maybe I was tired and need to check everything again.
        Many thanks for your help and kindness,
        Thanh-Nu

  24. Sherry said

    I have trouble with getting the logged on user – preferred name. I keep getting the user’s guid. I know I have the string right Value[Name="PreferredName"] But it still pulls the guid instead.

    Any ideas?

    • Clayton Cobb said

      Sherry, that tells me that your profile import is somehow putting a GUID into the PreferredName attribute field for users. That may be due to how your AD is setup. What happens when you specify other fields like WorkEmail, LastName, FirstName, Manager, AccountName, and GUID?

    • Clayton Cobb said

      Sheryl, when I reviewed your form, this is what I found in your default value statement:

      xdXDocument:GetDOM(“GetUserProfileByName”)/dfs:myFields/dfs:dataFields/s0:GetUserProfileByNameResponse/s0:GetUserProfileByNameResult/s0:PropertyData/s0:Name = “PreferredName”

      You had this as an expression in the filter on the “Value” node of the GetUserProfileByName web method. It’s not supposed to be an expression, but rather you select the “Value” node, then click filter, then select the “Name” noded and set it equal to “PreferredName.” Once I changed this on your form, it worked. Before doing that, it gave me the GUID. Were you intentionally setting those expressions on your fields insted of using the method on Itay’s blog that I link to in my blog?

  25. Sherry said

    Any type of name request, including manager, gives me the guid. If I set it for guid, I get nothing.

    • Clayton Cobb said

      Hmm, that’s pointing me more in the direction of a messed up profile import. Check these things:
      1) Click on someone’s name somewhere in SharePoint. This should take you to their profile (not their MySite). Do you see things like WorkEmail and all the other attributes in their profile?
      2) In your SSP Admin, go to User Profiles and Properties > View User Profiles. Find a user and click Edit Profile. Do you see the proper data in here, or do you just see that GUID in each box? Check for multiple, random users.
      3) Use my technique in the blog to send a different username to verify that you only see GUIDs for every user, not just your username

      If none of this leads to an answer, send me your XSN – use my Contact page.

  26. Thanh-Nu said

    Hi Clayton,
    I have used this formula to obtain a list of email from a repeating table:
    eval(eval(GrpTechDept; ‘concat(my:TechEmail, “;”)’); “..”)
    I got a resulting list like this:
    “email1@blabla.com;email2@blabla.com;email1@blabla.com”
    Now I would like to remove the duplicate email from this list. Is there a trick to improve the formula above to prevent concatenating duplicate value (codeless of course).
    Otherwise, do you think i should use XSLT to sort and filter the data to obtain what I want? If this is the case, do you have any pointer to working with XSLT in Infopath, because I don’t have experience in this area.
    Thank you in advance. Kind regards,
    Thanh-Nu

  27. Slinkydog said

    I am also getting 5566 error. The error states “An error occured accessing a data source”.

    My form is calling Getuserprofilebyname. The site collection in MOSS 2007 is an Intranet site so annonymous access is turned off. If I turn it on it works. I can’t have annonymous access turned on. Are there any ways around this?

    Thanks

    • Clayton Cobb said

      Slinkydog, are you saying that it ONLY works when Anonymous Access it turned ON? Can you double-check and verify that you aren’t getting backwards? That is the exact opposite of the expected behavior. This web service does NOT work when Anonymous Access is turned on, and I’ve had it happen to me on multiple occasions. It’s an obscure but known issue, but you are saying that your environment is behaving in the exact opposite manner?

      By the way, just because you have anonymous access turned on at the web app level, that doesn’t mean people can access your sites anonymously. All that does is ALLOW for anonymous access to be given in site collections within that web application, so turning it on at the web app level is not a security problem.

      • Slinkydog said

        Yes. It only works if Anonymous Access is turned ON. It is turned on for both the Application as well as the Site Collection.

        The site is also customized to use OpenID through the extranet authentication provider.
        Other than that it is just a team site.

  28. Mark Bowman said

    Hi Clayton,

    Hope everything is going well. Just a question regarding Digital Signatures and Browser-based forms.

    I have a Leave Application form going, that the user can sign the details with their digital signature. I then have the user’s manager (using your methods) signing another “approval” section on the same form using views.

    However, it seems that any user can come along and remove these signatures; even though Microsoft themself state that “No one else can remove your signature”. This sounds great, if it only works.

    I’m at the stage where I’m using the Manager signature to sign the User signature; which actually makes that control read-only and unable to remove the signature. However, the manager signature is still able to be removed by staff.

    I might have to contact Microsoft RE this problem; but thought I might ask if you’ve come across this before, or have any insight,

    Cheers mate,

    Mark

    • Clayton Cobb said

      Mark, I have not encountered that. Perhaps ask on InfoPathDev.com and the Social MSDN/TechNet forums (Infopath sub-forum)

  29. BijNep said

    Hi Clayton,

    Thank you for the good work. It really works.

  30. BijNep said

    Hi Clayton,

    Is there any way I can retrieve State, City and Zip code from the user profile by using UserProfileservice web service?

    Is there any OOB web services that I can use to populate those three fields (State, City and Zip code ) that exist in Active Directory.

    Thank you
    BijNep

    • Clayton Cobb said

      You can use the UserProfileService if those fields are being used in AD. You will have to configure your profile import to pull those fields into SharePoint, and then whatever those fields are called in the SharePoint profile database will be what you use when retrieving the GetUserProfileByName data set.

  31. BijNep said

    Thank you Clayton for your quick answer.

    Yes these fields are used in AD but not sure how to import into Profile database.

    Could you please give a detail about

    “have to configure your profile import to pull those fields into SharePoint”

    thank you
    BijNep

    • Clayton Cobb said

      In the middle of a SP2010 admin session, so I can’t look at a 2007 farm to give exact steps, but you basically go into your SSP Admin page, then go to User Profiles and Properties. This is where you configure your profile import and profile properties. You’ll need to create some properties in this area that are mapped to the proper fields in AD, or take existing unused properties in your SSP and map them to the AD fields. I can’t remember all of it off the top of my head, but that should take you in the right direction.

  32. BijNep said

    Thank you Clayton, for the write direction.

    BijNep

  33. Diptesh Bose said

    Boy! this is awsome. I implementation is so simple that we can build some robust workflow tools which i could not find in SharePoint Out-Of-the-Box workflows.

    I can now easily pull the Organizatio hierarchy and create custom workflow for multi-tier approval and this is all because of your simple implementation.

    Just let me know if i can send you some gifts..from India..

    Great Work.

    Thanks again.
    Diptesh

    • Clayton Cobb said

      Diptesh,

      Thank you for the kind words, and I’m glad this blog post was very helpful to you. The best gift from India that I can get is your testimonial about how much this impacted you. My goal is to eventually attain InfoPath MVP status, and it’s impact on the community that means the most.

      Thanks again!

  34. [...] And More Information on Getting User Information Without Code: Here are a couple more posts on getting user information from Itay Shakury and Clayton Cobb. [...]

  35. [...] And More Information on Getting User Information Without Code: Here are a couple more posts on getting user information from Itay Shakury and Clayton Cobb. [...]

  36. [...] And More Information on Getting User Information Without Code: Here are a couple more posts on getting user information from Itay Shakury and Clayton Cobb. [...]

  37. Tyler Hoffmann said

    Clayton,

    This is excellent, however I am experiencing the same exact issue as WK above.

    The following query failed: GetUserProfileByName (User: OSK\U99071, Form Name: PMO_ARR2, IP: , Request: http://oskmossd02/_layouts/WrkTaskIP.aspx?List=1f54d9ae-e87a-41b8-ada7-7565d0eea3a2&ID=982&Source=http://oskmossd02/explicit/Lists/Tasks/AllItems.aspx, Form ID: urn:schemas-microsoft-com:office:infopath:PMO-ARR2:-myXSD-2009-09-03T14-09-31, Type: DataAdapterException, Exception Message: The remote server returned an error: (500) Internal Server Error.
    Server was unable to process request. —> Attempted to perform an unauthorized operation.
    The remote server returned an error: (500) Internal Server Error.)

    Looking at the questions you asked him, here are my responses.

    - Is OSK\u99071 a local built-in admin account and not an AD account? You need to use a domain account that is in your profile import – a real user

    He is a test user but he has a real AD account and appears in my SSP

    - If this is a VPC without an SSP that has the profile import, then the web service is not available

    I’m on a VM with an SSP – Currently about 6k profiles imported

    - If your farm is normal, then take your UserProfileService URL and place it in a browser. Does it work? Do you get a page with the list of web methods?

    I as well as users who receive the error can get to the URL and see the list of actions.

    - Do you have a root site collection built at the root of your web app?

    Yes. I have a site collection at oskmossd02 and am using an explicit path to create oskmossd02/explicit

    - In your SSP Admin > Personalization Services Permissions, are Personal Features turned on? Does your user account have that permission? It is required.”

    NT AUTHORITY\Authenticated Users – Personal Features, Personal Site

    The one interesting thing of note, related to the users to be a REAL user as mentioned above, I have two users in which THIS DOES WORK. Interestingly enough while troubleshooting I read close to other peoples issues and noted the scenario in question and it turns out that the two users who work were the only ones imported at the time. Earlier today, I ran a full import and now have an abundance of users in my SSP but this issue still remains. I was thinking maybe there was some sort of service that had to kick off to trigger the new users to have appropriate permissions and so to speed things up I simply rebooted the server (its a development server). No luck unfortunately.

    Any thoughts? Thanks in advance!

    • Clayton Cobb said

      Tyler, so those first two users can interact with the web service, but no one else? Is that the case as of this moment – those two users can still use the web service?

      Do all users have read access to the root site collection? I assume so if those few test users can view the web methods in the browser. Whatever the root cause, it’s related to permissions/authorization. One quick test would be to raise the U99071 user to Site Collection Admin status and go from there. If that doesn’t even work, then we’re talking something more back-end.

      Is Anonymous Access enabled for this web app?

      • Tyler Hoffmann said

        You are amazing!

        It seems I was testing the url incorrectly. I directed it at the root of the server instead of the site itself. This is going to lead me to more testing but giving the users permissions at oskmossd02 did the trick. I will have to play around with my data connection and different permission levels needless to say.

        On the anonymous access part – Have you seen that if anonymous access is enabled for the web app that in ALL cases this service will not work? Currently, the web app in production allows for anonymous access but the site collection itself does not – as such, I am now a bit worried.

      • Clayton Cobb said

        It’s proper to point to the root, and then convert the data connection to a UDC. Just be sure all authenticated users have read access to the data connection library in your root site collection. Oh, also be sure to APPROVE the new DCL file, because content approval is automatically turned on in DCLs.

        Anonymous at the web app is different than at the site collection. It has been known NOT to work when enabled at the web app level, but you say that yours does work? Mine never has, and multiple times it has hit me in the face unexpectedly.

      • Tyler Hoffmann said

        Currently mine works because I do not have anonymous access enabled in my development environment. I had better test that really soon.

        What I am using the web service for is to determine if the current user is the approver for an approval workflow and if not, just to show them a generic properties view that I had created – This way, everyone can view tasks with a form that is bested suited for them! Is there a way to pull this off with anonymous access turned on?

      • Tyler Hoffmann said

        Did a quick test… and sadly it seems anonymous access destroys my functionality as well. I’m thinking I might have to do some negotiating internally here. Otherwise… do you have any recommendations for transferring a fairly large site collection to an entirely new web app?

  38. [...] the bottom. * This works at InfoPath as well as InfoPath Forms Services. *Clayton Cobb has a great follow up post if you to take the this a step [...]

  39. Brian said

    You can access the user login name from another source to get logon details. I had problems with infopath browser enabled forms with forms authentication for getting the user name or anything I could reference. I created my own user sqldb populated from fox pro which has all user info(cant access db from site at all, due to 64/32 bit issues). Then you add a loginName field to it. Then add a dataconnection to the login.asmx program, just like using the getuserinformation.asmx. Create a txtbox either mapped to loginname or a new txtbox or field mapped to it. The login name is in a subfolder called queries. This worked for me. It may not be the ideal solution, but none of the others worked whatsoever for me. It may give issues with anonymous, in fact it will, since there is no login to access. To control that you should design your site appropriately and create site collections for such forms that require authentication.

  40. [...] strip out the “DOMAIN” bit before the username use the substring-after command as detailed here. This gets the form looking neater, but when it is saved to the document library, the Manager field [...]

  41. Randy said

    I am definitely a fan of this WEB service. I have been using it extensively and have had only one issue to this point. When using a text box to enter the user name, if the user mistypes it, the control can not find the corresponding data. Do you know of a way to capture the fact that there was no result returned? The “Some Rules were not applied” error is bad, and I need to be able to trap this situation to provide a better user message.

    • Clayton Cobb said

      Randy, I would recommend not ever giving people a chance to type it in manually. You should make it dynamic always in this case. Give the users a Contact Selector so that they can choose users without mistakes, and then extract (use substring-after) the username from the AccountName node, set that value to the query node of the UserProfileService, then query.

  42. Clayton Cobb said

    Unfortunately, there can be many reasons for this error, but I can’t tell you what the problem is without looking at the system. Has this web service ever worked for you? Is this a browser form or rich client? Is Bevo in your datacenter wreaking havoc? Are you connecting from within the network with valid Windows credentials? For the Windows account that you’re logged into your machine as, does that exact username exist in the User Profile Database? You can check by going to the SSP Admin site > User Profiles and My Sites > User profiles and properties > View user profiles. Be sure your exact Windows ID is in there. It’s not your browser login, but rather the Windows ID.

  43. Clayton Cobb said

    Not that I know of. Having it enabled at all makes the web service inaccessible, or at least that has been a known issue for a few years and one that is impossible to troubleshoot without just “knowing” it. I learned it from a blog a long time ago. It’s possible that something in SP2 may have changed this, because I have seen one other person claim that this web service works even with anonymous access enabled. It has never worked for me when enabled at the IIS level (web app level).

  44. Clayton Cobb said

    Yeah, stsadm -o backup for the whole site collection, stsadm -o restore in the new web app, then stsadm -o deletesite after verifying the new location is working.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>