1

I have created a view that filters a list based on an OR condition between several columns using the [Me] keyword. I want to write the same kind of view, but that allows a person to be selected (i.e. allows you to view the items where another person has any of the roles).

I can do this in Access pointed against the list with the following query

SELECT [My List].[My Name], [My List].[Role 1], [My List].[Role 2], [My List].[Role 3], [My List].[Role 4]
FROM [My List] 
INNER JOIN [User Information List] 
ON ([User Information List].ID=[My List].[Role 1]) 
Or ([User Information List].ID=[My List].[Role 2]) 
Or ([User Information List].ID=[My List].[Role 3]) 
Or ([User Information List].ID=[My List].[Role 4])
WHERE UCase([User Information List].[User name])=UCase([USER_ID]);

but I can't figure out how to pass in the User ID as a parameter in SharePoint, perhaps it can't be done. It also occurred to me that grouping by this value would be sufficient, but I can't find a way to group by an or condition either...

1 Answer 1

4

I suppose you're looking for filter parameters.

You can pass a value to a list view using parameters. In SharePoint Designer they have the ribbon button for managing the parameters:

SPD Parameters button

So, you should navigate to a list edit page in SharePoint Designer, select your view, and then, select the XsltListViewWebPart element which represents your view in the page preview window.

Then, if you click the button, you can add a new parameter and select it's type.

enter image description here

For this example, I'm using Query String parameter, but for convenience, if you have SharePoint Server, you'd better add one of existing Filter Web Parts to the page, and use it in conjunction with a parameter of type 'None'.

If you don't like standard web parts functionality (I'm afraid as soon as User Information List is hidden, you can't reference it in OOTB SharePoint List Filter) or if you have Foundation (as do I), you will need to write your own webpart (implementing ITransformableFilterValues interface). You can find an example of doing this on MSDN:

So there, you should probably implement a very simple filter web part, with a dropdown list, filled from User Information List.

Anyway, after you have your parameter created, your second step will be to create the filter itself. Just click the [Filter] button on the SPD ribbon, and add filter rules for all 4 role columns, connecting them with 'Or' statements. You will be allowed to use the parameter in the filtering rules:

enter image description here

After applying the filtering, you can eventually go to your list view page, pass your parameter value, and get the result:

enter image description here

Here I'm passing the parameter using Query String, but as I previously stated, this can be done using user-friendly filter webpart.

4
  • sigh I'm guessing there's not a way to pull this off without Designer? Excellent answer though!
    – C. Ross
    Oct 2, 2011 at 23:38
  • Why not? You can go to Code tab in SPD and snoop the XML markup there. Based on this XML, it will be a rather obvious task to implement all the things programmatically, through SPLimitedWebPartManager, ParameterBindings and CAML Query with {Param1} token. Or you can use the snooped XML in a module in Visual Studio and deploy it within a feature. Oct 3, 2011 at 10:23
  • unfortunately I don't have access to any of those a the moment, thanks for the options!
    – C. Ross
    Oct 3, 2011 at 10:30
  • Oh, I regret you're out of the luck then :( The only way in this case is to use the OOTB filter web parts. This possibly will work (I don't have any experience with that because I'm a Foundation guy, and Filter web parts are avaliable only in Server version of SharePoint) Oct 3, 2011 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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