RSS Feed Feed your read!

Bookmark and Share







Tag Cloud

ASP.NET Generic, Best Practices, Business Intelligence, Freeware Releases, InfoPath, Infrastructure, jQuery, Lunch & Learn Events, Project Server, Random, Reporting Services, Search, SharePoint Administration, SharePoint Business Analysis and Project Management, SharePoint Development, Silverlight, Social Networking, Speaking Events, White Paper Releases, Workflow Foundation,

Archives

June 2007 (3)
August 2007 (1)
November 2007 (2)
February 2008 (2)
April 2008 (5)
May 2008 (7)
June 2008 (8)
July 2008 (7)
August 2008 (3)
September 2008 (7)
October 2008 (1)
November 2008 (3)
December 2008 (3)
January 2009 (7)
February 2009 (5)
March 2009 (10)
April 2009 (2)
May 2009 (6)
June 2009 (3)
July 2009 (4)
August 2009 (6)
September 2009 (3)
October 2009 (9)
November 2009 (10)
December 2009 (1)
January 2010 (1)
February 2010 (3)
March 2010 (6)
April 2010 (2)
May 2010 (3)
June 2010 (4)
July 2010 (3)

SharePoint Cross Site Lookup Columns with jQuery 

Tags: jQuery, SharePoint Development

Ever want to use a lookup column in SharePoint to lookup data in a list, but that list resides in a different site collection or site than the one you're in? Well – out of box this isn't possible, but with the help of jQuery and an event handler, it certainly is possible!

 

The basic idea behind the solution is to use a text column instead of a lookup column, and as the user starts typing in the text column, a Web Service request will fire to the remote site via jQuery to retrieve a list of "Lookup Values" to present to the user in an Auto-Suggest box.

 

For example – say you have a site with a list in it that contains a list of Projects. Then, in another site that contains Project Documents, you want to associate a particular document with a Project ID from that other site.

 

 

All you have to do is start typing the project name in the ProjectID column for that document and the Auto-Suggest box will populate with suggestions based on your search term.

 

 

Then when you click an item in the Auto-Suggest box, it will put the Project ID into the Project ID column.

 

 

Pretty slick huh? There is one more important aspect of the solution however. As you can tell, a user could easily type in something that is not a valid project ID – so I also included an event handler that executes after the user hits OK. This event handler queries the lookup column list for the value that was typed, and if it is not found, it presents an error to the user that they didn't type a valid ID.

 

To Download my Visual Studio Project

 

http://philwicklund.com/Downloads/CrossSiteLookups.zip

 

Installation Instructions

 

Download project and open the LookupProjectID.js file under TEMPLATE\Layouts\Happenings. Edit the following fields to point to the SharePoint list you want to lookup data from:

 

var urlToWeb = "http://localhost:82";

var listName = "Project List";

var lookupValue = "Title";

 

 

In the same file, edit the callingColumnName to specify what text field in your edit form(s) is performing the lookup (this is how the Auto suggest box knows where to position itself):

 

 

var callingColumnName = "ProjectID";

 

 

Under the EventHandlers folder in the visual studio project, open the ConfirmLegitProjectID.cs event handler. Edit the following values to point to the SharePoint list you want to lookup data from:

 

public override void ItemUpdating(SPItemEventProperties properties)

{

// EDIT THIS!

string lookupListName = "Project List";

string lookupSiteURL = "http://localhost:82";

string lookupWebURL = "";

 

In the same file, edit the callingColumnName to specify what text field in your edit form(s) is performing the lookup:

 

string callingColumnName = "ProjectID";

 

Build the Visual Studio Project (this spits out a wsp solution file at c:\wsp). Add the solution to SharePoint (stsadm -o addsolution). Deploy the solution via central admin (or -o deploysolution). Activate the feature on the site(s) you want to lookup the data:

 

 

DONE!

 

Credits

 

I have to give credit to Timothy Groves for providing the jQuery Auto-Suggest box, as well as Jan Tielens for his write-up on jQuery and web service calls.

 

 

Cheers!

 

Phil

 
Posted by BENDER\pwicklund on 8-Sep-09
0  Comment  |  Trackback Url  | 0  Link to this post | Bookmark this post with:        
 
Failed to render control: Value does not fall within the expected range.

Comments

Bookmark and Share

Note: Facebook no longer sends notifications for comments, so it may be a number of days before I see your post. For urgent matters, click "Contact Me" on the top nav. More info: Click Here.