Use the SharePoint '[Me]' Filter with a Promoted Property - Greg Collins
in

InfoPath Dev

This Blog

Syndication

Greg Collins

Use the SharePoint '[Me]' Filter with a Promoted Property

When saving InfoPath forms to SharePoint document libraries you might need to limit the forms users see. For example, if you have an established workflow, you might want to limit users to see only those forms that are assigned to them.

SharePoint provides a special filter so that users can see, for example, only those items that they created or modified, for example. This is known as the 'Me' filter. Attempting to use this filter with promoted properties, such as the user name, fails, and the SharePoint view renders the text <!-- #RENDER FAILED -->. This is because the 'Me' filter only works with SharePoint user IDs, not user names.

In this task, we will create a simple InfoPath form that will present a list of SharePoint users and promote the selected user name and ID. We will publish the form to a SharePoint form library and then modify the default view to filter the list based on the logged in user. You will need access and rights to an available SharePoint to complete this task.


THE INFOPATH FORM

First we will create a very basic InfoPath form that allows you to assign the form to a SharePoint user. To get the list of SharePoint users we need to manually modify the form manifest as the SharePoint user list is not available via the designer. Let's start by designing a new blank form.

Create the schema:

  1. Open the Data Source task pane.
  2. Add a two Text fields named FormTitle, AssignedTo.
  3. Select AssignedTo, and add a Text Attribute field named id.

Create the view:

  1. Right-click FormTitle, choose Text Box, and then press Enter.
  2. Right-click AssignedTo, and then choose Drop-Down List Box.

Add a SharePoint list data connection:

  1. Double-click the drop-down list box.
  2. Select Look Up Values In A Data Connection, and then click Add.
  3. In the Data Connection Wizard, select SharePoint Library Or List, and then click Next.
  4. Type the URL to your SharePoint site, and then click Next.
  5. Select any list or library, and then click Next.

It does not matter which list or library you select as we will be manually modifying it later to get the list of SharePoint users.

  1. Ensure that only the ID and Title check boxes are selected, and then click Next.
  2. Name the data connection SharePoint Users, and then click Finish.

Populate the drop-down list box using the new data connection:

  1. Click the Select XPath button to the right of the Entries text box.
  2. Select :Title, and then click OK.

Set the ID when Assigned To changes:

  1. Click Rules, and then click Add.
  2. Name the rule Set ID, and then click Add Action.
  3. In the Action dialog box, select Set A Field's Value from the Action drop-down list.
  4. Click the Select XPath button to the right of the Field text box, select AssignedTo/id, and then click OK.
  5. Click the Insert Formula button to the right of the Value text box, and then click Insert Field Or Group.
  6. In the Select A Field Or Group dialog box, select SharePoint Users from the Data Source drop-down list.
  7. Select :ID, click Filter Data, and then click Add.
  8. In the Specify Filter Conditions dialog box, select Title from the first drop-down list, and then select Select A Field Or Group from the third drop-down list.
  9. In the Select A Field Or Group dialog box, select Main from the Data Source drop-down list, and then select AssignedTo.
  10. Click OK nine times to close all the open dialog boxes.

Promote the form fields to SharePoint:

  1. Select Form Options from the Tools menu.
  2. On the Form Library Columns tab of the Form Options dialog box, click Add.
  3. Select FormTitle, and then click OK.
  4. Click Add, select AssignedTo, name the column Assigned To, and then click OK.
  5. Click Add, select AssignedTo/id, and then name the column Assigned To ID.
  6. Click OK twice to close all to close the open dialog boxes.

Extract the form files:

  1. Choose Extract Form Files from the File menu.
  2. Select a location to save your extracted form files to, and then click OK.
  3. Close InfoPath to release the lock it places on your form files.
  4. Using a text editor, open your manifest.xsf file.
  5. Search for the text sharepointGuid.

This is an attribute on an xsf:sharepointListAdapter object with the attribute name="SharePoint Users".

  1. Change the value of the sharepointGuid attribute to UserInfo. The updated attribute should look like the following:

sharepointGuid="UserInfo"

  1. Save the manifest.xsf file, and then close the text editor.
  2. Reopen your form template by right-clicking the manifest.xsf file and choosing Design.

You have now a drop-down list box populated with a list of SharePoint users. Preview your form to test it. You might find some systems users such as NT AUTHORITY\NETWORK SERVICE in your list. These can be hidden by adding a filter to your drop-down list box.

Publish your form to your SharePoint, close your form, and then open your form from its published location.


THE SHAREPOINT FORM LIBRARY

Fill out the form a few times, assigning each to different users and saving back to the form library. Finally, click All Forms to refresh the view. You should now see each of the forms you just saved, including the promoted properties for Title, Assigned To and Assigned To ID. Now let's update the default view so that it does not show the Assigned To ID field and only displays forms assigned to you.

Update the default SharePoint view:

  1. Click Modify Settings And Columns.
  2. Click All Forms in the Views section.
  3. In the Columns section, clear the Assigned To ID check box.
  4. In the Filter section, select Assigned To ID from the first drop-down list, and then type [Me] in the text box.
  5. Click OK, and then click the Go Back To link at the top of the page.

The default SharePoint view now automatically filters items to only show those assigned to the currently logged in user—you in this case.

©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

Comments

 

Martin said:

Been using this method for quite a while under WSS2, but with WSS 3.0 it doesn't appear to work any more.

The columns are promoted as "Single line of Text" and the [Me] filter isn't valid for anything other than "Person or Group" columns.

Is there a way to force the system to pick up my promoted properties as "Person or Group"?

I've located the promoted column definitions in properties.xfp in the list directory, but can't find any valid options that prodce a "Person or Group" column (though I can change it around from text to number and that works)

April 16, 2007 2:23 PM
 

sirwally said:

Martin,

I have found that a good solution to this problem is to create a Filter Web Part.  I recently created one that returns the NT username of the current user.  MOSS actually provides this out of the box, but WSS does not.  Once the the web part is installed, you can add it to a page and then connect it to other web parts on the page that you wish the filter.  One caveat to this method is that the filter is always active.

I'd share my code if I could (it was developed for a client), but it was really easy to develop.  See the following links to step-by-step instructions:

Writing a Filter Provider Web Part for Windows SharePoint Services 3.0

http://msdn2.microsoft.com/en-us/library/bb457205.aspx

Deploying and Optimizing a SharePoint Web Part That Calls Excel Web Services

http://msdn2.microsoft.com/en-us/library/aa973805.aspx

Hope that helps,

Simon.

June 13, 2007 5:20 PM
 

solo42 said:

Great article, only that I still get <!-- #RENDER FAILED --> when trying to filter with [Me]. I have managed to get the user from SharePoint into my dropdown, and the AssignedTo column value in SharePoint is "Doe, John" just as I would like it. However, the ModifiedBy column for example also has the value "Doe, John", but here it is a clickable link whereas in the AssignedTo column it just seems to be text.

Also, it is possible to select only users from a certain group?

Regards, Helena

June 26, 2007 1:17 AM
 

jeagly said:

Hi Greg,

My form works but when I tried to publish it to the SharePoint site, I got the following error.

InfoPath has encountered an error. The operation failed. Access is denied.

I have been able to upload other forms to this site before. Why can't I upload this form and what is the fix for that?

Thanks

July 10, 2007 1:27 PM
 

jeagly said:

Never mind I got it. I was not selecting the Form library. sorry!

July 10, 2007 1:37 PM
 

jeagly said:

Hi Greg,

Is there a way to set it up where only the Assigned To receives an email when selected?

July 10, 2007 1:45 PM
 

zullu said:

Hi Greg,

I would like to know something about the "PROMOTED COLUMNS".

Is it true that I can't update a promoted column from my VS2005 code?

It shouldn't be, else this would be a real handicap to a developer.

I have a InfoPath 2003 Form. I have published the form to sharepoint 2007 Form Library.

While publishing, I have promoted few columns to appear as the library columns. (for instance, "varApproveRejectStatus")

Now I am trying to update that column from a web part using C# from VS2005.

Code snippet:

.........

........

myItems = master.GetItems(query);

foreach (SPListItem item in myItems)

{

    item["varApproveRejectStatus"] = "COMM_PUBLISHED";

    item.Update();

}

.............

.............

Here is the problem.

The promoted column "varApproveRejectStatus" is not updated even after the execution of the item.Update();

If I use the "Title" column of the Form Library to update (which is not the promoted column), the update works superbly.

Is this a known bug in MOSS or really updates to promoted columns are not allowed.

I would be crossed to know that MOSS doesn't support this kind of updates.

I very badly need to update this as this would trigger my workflow to move ahead.

Any help!!!

Thanks in advance.

zullu

July 11, 2007 12:04 PM
 

Craig Schaefer said:

Is there a way to have the list of Users sorted?  Right now they come back ordered by their ID.

December 5, 2007 10:11 AM
 

Yurnero_ said:

What if we want to make a filter on lets say a manager. For example if managers have to validate forms, how to filter and show to the mangar only the forms from his team member. I tried with SP ID Name or Account extracted and then promoted but this dont work...

June 12, 2008 5:38 AM
 

JeniEck said:

This works fine for me in preview on my machine. However when I publish it to my forms library I get the following error. Have I missed something?

-------

Warning

There has been an error while processing the form.

Click Continue to resume filling out the form. You may want to check your form data for errors.

Click Start Over to load a new copy of the form.

Show error details

An error occurred accessing a data source.

An entry has been added to the Windows event log of the server.

Log ID:5566

-----

Thanks

Jeni

July 23, 2008 3:52 AM
 

JeniEck said:

Hi Greg,

Please can you help with this? Your code works perfectly in preview from Infopath but when I publish it to my moss 2007 forms library I get the message shown in my previous post.

I can click continue and fill out the form but I do not get the drop down list of sharepoint users?

Any ideas?

Thanks

Jeni

July 24, 2008 1:42 AM
 

briwagner said:

I have duplicated your steps in InfoPath 2007 with WSS 3.0 and I get some usrs listed in the dropdown list but not all, it cuts off after 100.

Is this supposed to happen or am I missing a setting in WSS somewhere?

I did add the data as a repeting table to verify it was not a control liitation and the table stops at 100 as well.

Thank you,

Brian Wagner

November 13, 2008 11:25 AM
 

briwagner said:

Nevermind I found where the SharePoint User Info List was being limited to 100 items.

Brian Wagner

November 13, 2008 12:59 PM
 

johnb said:

I added this to a form I'm creating for my team and it seems to work, but it promoted an ID number in the Assigned To ID field and not the user names; thus I can't use the [Me] filter...for the life of me I can't figure out where I went wrong...any advice is greatly appreciated

March 1, 2009 4:36 PM
 

Blog of an overweight SharePoint addict » Infopath forms with User ID’s said:

Pingback from  Blog of an overweight SharePoint addict &raquo; Infopath forms with User ID&#8217;s

September 30, 2009 2:00 PM
 

handaman said:

I've attempted your steps using MOSS and IP2k7 and am not able to get the [Me] filter to work.  The Assigned to Id field is a ##, when i add the [Me] filter i get "Filter value is not a valid text string.  What step am i missing?

Thanks

March 17, 2010 10:28 AM
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.