Wednesday, July 10, 2013

Cross-site Lookup column for SharePoint 2013 and SharePoint Online in Office 365

In this article I would like to present our new solution Cross-site Lookup for SharePoint 2013 and SharePoint Online in Office 365. With help of this feature you can create lookup columns with quick search and asynchronous loading of results for lists and libraries to link data from any sites within a site collection.

First, I would like to cover the technical aspects of this solution. Our lookup is not a custom field because custom fields can be deployed only as part of farm solutions which are not available for Office 365. So, we made it as a number of JavaScript templates (view, edit, new and display) for standard Lookup field. We used JSLink property of SPField class to inject these templates and Select2 control with some modifications as control for searching and navigating through the source list.

Now I will demonstrate our solution in action. In the root web of the root site collection I created a list of countries. Next I created a new site collection in the same web application and added a custom list to its root site and named it Target. Ok, let's create a new lookup column in Target list which links to Countries list in the root site collection.

Open the view of Target list and click 'Plumsail Lookup ' button in 'List' tab of the ribbon.

SharePoint 2013 Cross-site Lookup

If you don't have the existing lookup column in your list you will see a dialog for creating a new lookup field. Enter the name of this field in text box and click Ok.

Create cross-site lookup in SharePoint 2013

After the field has been successfully added you can configure it. First, let's change the source list. Click 'Change ' link near the web url to specify the web of your source link. I clear this field because my source list is located in the root site of the root site collection. Ok.

Now select the source list in the next dropdown and the field of the source list which will be shown in the target list. In my case the source list is Countries and the field is Title. Ok.

Cross-site lookup column for SharePoint 2013 settings

By checking appropriate options you can enable multiple values for your lookup and add 'New Item' link which allows users to add new items to the source list directly from the form.

If you check Add 'New Item' link you will see the following options:

SharePoint 2013 lookup with add new item link option

In the first field you can specify the title of the new item link. The second one is for default content type ID. When the user clicks the new item link they will see a form for the specified content type. If you leave this field empty, users will see a form for the default content type of the source list.

Here is what this link looks like in the form:

SharePoint 2013 lookup with add new item link

I will cover Advanced section fields in the next article. Now, let's see what our lookup field looks like in forms and list views.

Lookup column with a single value:

SharePoint 2013 lookup with single value

Lookup column with multiple values:

SharePoint 2013 cross-site lookup with multiple values

List view:

SharePoint 2013 cross-site lookup in the list view

Display form:

SharePoint 2013 cross-site lookup in display form

Looks perfect. In the next articles I will demonstrate how to change the template of the result set in the select box of Cross-site Lookup Column, how to use Lookup and Forms Designer together and create dependent columns and cascading dropdowns.

4 comments:

  1. I followed your instructions and configured one of my lookup fields as a Plumsail lookup so I could add the Add New Item link to it. Now when I open the form to add a new item, the lookup fields just show a spinner instead of the drop-down. This is in SharePoint Online.

    ReplyDelete
    Replies
    1. Hi,
      Have you modified the Advanced settings?
      Please, open the lookup manager, expand 'Advanced settings' section and click Reset in both 'Request items' and 'Item format' templates. Next, save the field and try again. If it does not help, contact us by support@spform.com.

      Delete
  2. Is it possible to display in drop down only unique entries excluding duplicates?

    ReplyDelete
    Replies
    1. I believe that this is a design issue having multiple identical entries in a list. They have different IDs, so which should be displayed in the drop-down? I recommend you to either add 'unique' constraint to the column of the source list, or add a third list as a dictionary and a reference to this list from the current list.

      Delete