Good day all, I bring you another tweak for Sharepoint. In
Sharepoint 2010 and Cascade Lookups I've shown you how to filter a lookup column based on the value of another. Now, what if you want to filter a column, based on a query of the source list?
There are plenty of options over the web on how to do it using third-party tools. In my opinion it is always good to avoid that. Why? Well in the past I had huge problems with third-party tools, specially restoring sites with those features.
There are plenty of options over the web on how to do it using third-party tools. In my opinion it is always good to avoid that. Why? Well in the past I had huge problems with third-party tools, specially restoring sites with those features.
So, now, I always try to avoid third-party tools unless I've no other option.
Check how I filter columns based on queries in 6 easy steps:
Ok you have two lists connectec by a lookup column:
List 1: Parent list
List 2: Child list connected to List 1 by ColumnA column
And now, when you are adding or editing a new item in List 2, you want to allow only to pick List 1 Active items.
Solution
1. Open your site in Sharepoint Designer
The first step is to open your Sharepoint site in Sharepoint Designer 2010.
In the Site Objets pane select Data Sources, there your should have one data source for each List in the site.
2. Duplicate List1 data source
Right click in your parent list data source, ours List 1, and click in Copy and Modify
In General tab give your data source a unique name and define in Source tab the filter you want. In our case "State Equals 'Active'", like this:
3. Create new custom forms
In your child list, our List 2, create new custom forms, for New and Edit item. Repeat steps 4 to 6 for each form. Don't forget to make the new custom forms the default ones.
4. Delete the Form Field of ColumnA
Edit your form and delete the Form Field associated to ColumnA
5. Insert a new data source
In the Insert tab, insert a new data source and pick the one you created in step 2.
6. Insert a Sharepoint Drop Down control
After inserting the data source, go again to Insert tab and insert a Data View DropDownList from Sharepoint controls.
Ok now that you added everything needed, you just need to configure the newly added field to map the fitlered data source. Pick the field and click Data Fields ... link
In data field, pick the lookup column.
In data source, pick the data source added in step 5
For the display text, pick the field you want to be displaied to the user
For the field value, pick the value passed to the lookup column, tipically ID field.
Ok save everything and go to your site. You should be getting something like this:
ColumnA only shows items from List 1 which State field has the value Active.
Hope you enjoyed it and if you want to see this working, download the following site template Filter Lookup Site Template.
NOTE: This is an english template, if that is not your Sharepoint installation language you will need to install the English Language Pack, check it how in here.
Sounds very interesting. Does this work also in Sharepoint 2007?
ReplyDeleteHi Michael, thanks for stoping by.
DeleteSaddly can't try if it works on Sharepoint 2007, but it should. The function Copy and modify a data source should also be available in Sharepoint Designer 2007.
This works excellent, however when I use this on the Edit form I get an error: "An unexpected Error has occured.
ReplyDeleteWeb Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator."
Hmm ... let me take a look at it. I'll return soon.
DeleteOk, I've tried this in Edit Form and it worked like a charm, can you give me more details about your case.
DeleteGreat, this is exactly what I was after. Worked perfectly for me (using SPF 2010) thank you very much indeed for posting!!
ReplyDeleteHi Pedro
ReplyDeleteThanks for posting this - works great!
I'm looking forward to dig into the rest of your posts ;)
Best regards,
Patur
Welcome Patur, glad you stopped by.
Deletewhen you edit current inserted record how to set lookup field,Because i set these fields but getting hyperlink on it… if you have any solution about that problem post the comment…
ReplyDeleteHi Mani, take a lookup at this article http://howididit-sharepoint.blogspot.pt/2012/08/removing-html-tags-drop-down.html.
DeleteThis comment has been removed by the author.
ReplyDeleteMy solution was in the previous post.
DeleteHi Joshua, nice to see you here.
DeleteHi,
ReplyDeleteI gave this a try and for the most part it works great. My only issue is when I go back and edit a record that has a value that was active and now is not.
Using your example, I have a record that has List1/Item1
Now List1/Item1 is inactive. When I edit the record I thought the dropdown would only have the active values but instead it has the <a onclick="OpenPopUpPage('http://Mysharepoint/page/_layouts/listform.aspx?PageType=4&ListId ..... as the first choice then the correct choices. Could I be doing something wrong? thanks
Hi, that's true I've managed to solve it in this post: http://howididit-sharepoint.blogspot.pt/2012/08/removing-html-tags-drop-down.html
DeleteExcellent! thanks! works great!
DeleteHi, I opened a sharepoint online (365) site on SPD and when I select the dropdown the right arrow and the option Data Fields are not showing. Maybe because I'm using SP Online?
ReplyDeleteThere is another way to configure the data field?
If you don't have any way to access the data fields you could achieve the same using javascript and webservices.
DeleteI've been using javascript to filter the dropdown list options, also. Yet it turns to have some problems in clientes machines where the internet security is set to very high.
I'll try to post today a new article showing how to do the same filtering using javascript.
Thank you for this!!! I've almost got it working the way I need...but I can't figure out how to allow for multiple selections on the newly-added dropdown list. Is this possible or is there a different control I should be using to mimic the standard selection list boxes?
ReplyDeleteBy the way, I'm using 2007 and you were right that the steps you listed translate from 2010 - though everything is in a different place or under a different menu obviously :-)
Once again, thanks!!
I've almost got it working. I was also trying to "allow multiple values" and couldn't figure out how to do it.
DeleteI have a list for issues where I want to have one or more related tasks from another list. I only want the choices to show tasks that have not been completed. It is possible to have multiple tasks related to one issue. So I want it to look like the Predecessors field on the standard task list.
Thanks for any help you can give. Cheers.
This worked perfect! I played with jquery all day long... this took 2 minutes!!
ReplyDeleteThank you soooo much!
So I said this worked perfect, but that was for the New Item form. When i do this to the edit form, it doesn't retain what was selected when I created the item. It's blank... any ideas?
ReplyDeleteHi, by the way you describe the issue. It might be something in the databinding in the New Form. Could you please send me screenshot of it?
DeleteLooks promising but when I go to add the SharePoint control (drop down list) I can't. The HTML and ASP.Net controls work fine, but not the SharePoint one, any ideas?
ReplyDeleteHi Pedro,
ReplyDeleteIs it possible to use a list box control, instead of a drop down list, and set it up to allow multiple values?
Hi Pedro,
ReplyDeleteDo you have any inputs on how to filter a list column using Javascript? My client wants to filter a report (that is pulled from a list), based on one of the columns of a list !
Thanks and that i have a swell provide: Who Repairs House Siding home remodeling services
ReplyDelete