Function
$().SPServices.SPDisplayRelatedInfo
Functionality
SPDisplayRelatedInfo is a function in the jQuery Library for SharePoint Web Services that lets you display information which is related to the selection in a dropdown. This can really bring your forms to life for users: rather than just selecting bland text values, you can show them images and links that are related to their choices.
How Does It Work?
The SPDisplayRelatedInfo works like this:
- When the function is first called, it attaches an event handler to the dropdown control. The logic here varies a bit depending on what type of dropdown it is.
- When the selected option in the dropdown changes, SPDisplayRelatedInfo calls two Lists Web Service operations:
- GetList on the relatedList to get information about its columns (fields)
- GetListItems to get the items where the specified column’s value matches the current selection. Note that there can be multiple items returned; generally displayFormat: “table” makes more sense if you’ll want to display multiple items.
- For each column it’s asked to display, SPDisplayRelatedInfo calls a private function (showColumn) to render the column value based on its type. Most of the normal column types are covered, though locale conversions can’t be done from the client side (yet!). The related information is shown in a DIV which is inserted into the form. The DIV is named 'showRelated_' + columnName in case you need to do any post-processing.
Tip: If you don't want to see the column headers, pass in ms-hidden for headerCSSClass. (This is a CSS class in core.css which sets display: none.)
Prerequisites
- You'll need to have a list (relatedList) which contains the values in the dropdown in one column and the related values you'd like to display in additional columns. If you're already using SPCascadeDropdowns, then you'll already have a list (or lists) in place which you can use here.
Here is an example of the form where you want to use SPDisplayRelatedInfo:

In this example, I have a list called Systems, which has three columns:
Syntax
$().SPServices.SPDisplayRelatedInfo({
columnName: "",
relatedWebURL: "",
relatedList: "",
relatedListColumn: "",
relatedColumns: [],
displayFormat: "table",
headerCSSClass: "ms-vh2",
rowCSSClass: "ms-vb",
numChars: 0,
matchType: "Eq",
CAMLQuery: "",
completefunc: null,
debug: true
});columnNameThe
DisplayName of the parent column in the form
relatedWebURLThe URL of the Web (site) which contains the relatedList. If not specified, the current site is used. Examples would be: "/", "/Accounting", "/Departments/HR", etc. Note: It's always best to use relative URLs.
relatedListThe name or GUID of the list which contains the related information. If you choose to use the GUID, it should look like: "{E73FEA09-CF8F-4B30-88C7-6FA996EE1706}". Note also that if you use the GUID, you do not need to specify the
relatedWebURL if the list is in another site.
relatedListColumnThe
StaticName of the column in the related list
relatedColumnsAn array of
StaticNames of related columns to display
displayFormatThe format to use in displaying the related information. The default is "table". The displayFormat takes one of two options:
- “table” displays the matching items much like a standard List View Web Part would, in a table with column headers
- “list” also uses a table, but displays the item(s) in a vertical orientation
headerCSSClassIf specified, the CSS class for the table headers. The default is "ms-vh2".
rowCSSClassIf specified, the CSS class for the table cells. The default is "ms-vb".
numCharsIf used on an input column (not a dropdown), no matching will occur until at least this number of characters has been entered. The default is 0.
matchTypeIf used on an input column (not a dropdown), type of match. Can be any valid CAML comparison operator, most often "Eq" or "BeginsWith". The default is "Eq".
CAMLQueryThe CAMLQuery option allows you to specify an additional filter on the relationshipList. The additional filter will be <And>ed with the existing CAML which is checking for matching items based on the parentColumn selection. CAMLQuery should contain a CAML fragment such as:
CAMLQuery: "<Eq><FieldRef Name='Status'/><Value Type='Text'>Active</Value></Eq>"
completefuncIf specified, the completefunc will be called each time there is a change to columnName. Potential uses for the completefunc: consistent default formatting overrides, additional lookup customizations, image manipulations, etc. You can pass your completefunc in either of these two ways:
completefunc: function() {
...do something...
},
or
completefunc: doSomething, // Where doSomething is the name of your function
debugSetting
debug: true indicates that you would like to receive messages if anything obvious is wrong with the function call, like using a column name which doesn't exist. I call this
debug mode.
Example
$().SPServices.SPDisplayRelatedInfo({
columnName: "System",
relatedList: "Systems",
relatedListColumn: "Title",
relatedColumns: ["System_x0020_Image", "Lead_x0020_Sales_x0020_Rep"],
displayFormat: "list"
});So I’m asking SPDisplayRelatedInfo to show me the values in the
System_x0020_Image and
Lead_x0020_Sales_x0020_Rep columns (these are the
StaticNames of the list columns as opposed to the
DisplayNames) in the
Systems list under the
System column in my form using the
list display format where the
System value matches the
Title value in the
Systems list. I’m just taking the default CSS classes for the example. As you can see, you can pass in any CSS class you’d like to make the SPDisplayRelatedInfo output match your site branding.
