Case
Try to filter a lookup column within a standard SharePoint Edit Form just using JQuery and JavaScript.
Prerequisites
- You need a SharePoint Library to store your JavaScript and two JQuery Library’s
- You need a LookUp Column
- You need a Query List with a filter criteria
How it works
We have two lists, one list for your projects and one list for our tasks. Within the task list there is a lookup column which references to the project list. Our project list also stored the status of a project so we are able to see if a project is active, inactive or planed. As a result you should only get the active Projects e.g. P12-002-20 and P12-002-10 as options if you create a new task.
Sample Picture for Project List
Sample Picture for Selecting only the Active Projects
Step by Step
-
Create a library for all JAVA Script stuff
- Upload jquery.SPServices-0.7.1a.min
- Upload jquery-1.7.1.min
- Upload your JAVA Script File
-
Create a project list
- Add a choice field for project status
- Add a text field to store project number
-
Create a Task list
- Add a lookup column to the project list
- Reference to the project number field
-
Edit the default edit form for the Task list
- Add a CEWP Content Editor Webpart
- Reference the content of the CEWP to the JAVA Script File
- Now test your solution
Sample Picture for CEWP Settings
Sample Picture for JAVA Script Library
Sample Code
[sourcecode language=’JavaScript’]
$(document).ready(function() {
alert($().SPServices.SPGetCurrentSite());
});
$().SPServices.SPFilterDropdown({
relationshipList: “My Projects”,
relationshipListColumn: “ProjectNumber”,
columnName: “Project Number”,
CAMLQuery: “
completefunc: null,
debug: true });
[/sourcecode]
More information about $().SPServices.SPFilterDropdown: http://spservices.codeplex.com/wikipage?title=$().SPServices.SPFilterDropdown
Download sample text file sample_getformfields
..:: I like SharePoint ::..
Leave a Reply
You must be logged in to post a comment.