I have an InfoPath form with two views - one for viewing a SharePoint list items data (which only shows a few fields), the other for editing. What I want to do is to check if the current user of a SharePoint group, and if they have edit rights (i.e. they created the item). If they are in group 'X' and it is their list item, then allow the edit to take place (showing the extra fields). If not, prevent the edit form from showing (or show a form with readonly fields).

I can see that it is possible to add a connection to a web service (http://sharepoint2010/_vti_bin/UserProfileService.asmx), but how do you actually call the service before form load, i.e.

  1. Get current user
  2. Query Web Service for groups current user belongs to
  3. Get current list item 'Created By' user
  4. Show form 'A' (readonly) if user is member of group 'X' and 'Created By' is not the same as the current user
  5. Show form 'B' if member of group 'Owners' or 'Created By' is same as the current user

Any idea how I can go about this?

Calling username() does not return the domain, just the username. Also Created By is a person/group picker, how would you query that to get the AccountId (which is DOMAIN\username) to compare with the hidden field value?


If you make the connection, then you can create rules for how the form will load. In InfoPath Designer 2010, click on the Data tab at the top of the ribbon. The "Form Load" button will reveal the ability to create these rules and switch the views. It will make these checks when the form is loaded, not after. What you should do, though is use the username() function to populate a hidden field when the form is first created. This will save you from having to get the list item information, you will already have it populated within your form, then just compare the username property with the username hidden field when you open the form. One word of caution here, you may need to normalize the username from both fields as the logged in username is usually saved in all lower case, and the username from the profile may be lower and upper case. Another option is just to compare the function username() with the hidden field instead of pulling it from the profile. This might make the form load a little faster.

As far as the groups go, you will probably have to use a rule where the field in the profile contains the group you are referencing. However, if the user is a member of both groups, make sure you place the rules in the order you wish for them to be executed and then make it stop processing rules. This could cause unexpected behaviors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.