Interesting New Uses for SPDisplayRelatedInfo

I had a question on my recent article over at EndUserSharePoint.com entitled A jQuery Library for SharePoint Web Services (WSS 3.0 and MOSS): Real World Example – Part 1.  The question was about the SPDisplayRelatedInfo function, and while I was setting things up to see if I had a bug, I found that there were some interesting ways you could use the SPDisplayRelatedInfo function that I hadn’t considered.

I added a Single line of text column to my old standby Sales Opportunities list and called it StateID.  In my EditFormCustom.aspx, I added this call to SPDisplayRelatedInfo:

$().SPServices.SPDisplayRelatedInfo({   
    columnName: "StateID",
    relatedList: "States",
    relatedListColumn: "ID",
    relatedColumns: ["ID", "Title"],
    displayFormat: "table"
});

The States list is one of the lists I use in testing SPCascadeDropdowns, and it has these columns: State (the original Title column) and State Abbreviation. Now, when I typed digits into the StateID column, I got real-time results from the SPDisplayRelatedInfo function as the digits matched the ID of the State item. Cool!

So if I started out with the column empty, I saw:

image

then when I typed 1:

image

then when I typed 2:

image

This also worked if the StateID column was a Number column.  Looking through the code, there was no reason this shouldn’t work, it’s just not the use I had intended.

So then I thought, well what if I wanted to match as I type the State?  I switched the function call to this:

$().SPServices.SPDisplayRelatedInfo({   
    columnName: "StateID",
    relatedList: "States",
    relatedListColumn: "Title",
    relatedColumns: ["ID", "Title", "State_x0020_Abbreviation"],
    displayFormat: "table"
});

Then when I typed Massachusetts, I saw:

image

Hmm, that can’t be right.  I went and checked the States list, and sure enough, I had some junk test data in there that I had forgotten about.  Even cooler!  The SPDisplayRelatedInfo function essentially acts like an as-you-type reference lookup!

These examples aren’t exactly what you’d be doing in the real world, but think about the situation where you had a product code that could be 1-5 digits or numbers or something where you wanted to let the user type instead of dealing with a dropdown. If you come up with another interesting use, let me know about it.

It’s always nice to find out that code you’ve written is *more* useful than you thought (as opposed to the dreaded less useful situation).

Similar Posts

8 Comments

  1. Hello,

    I would like to implement your idea but it does not run for me… :-(
    I add a content Editeor Web Part on my page and add this source code :

    $().SPServices.SPDisplayRelatedInfo({
    columnName: “idville”,
    relatedList: “CascadeVilles “,
    relatedListColumn: “ID”,
    relatedColumns: [“ID”, “Title”],
    displayFormat: “table”
    });

    2 lists :

    – QueryVilles : Title, IdVille

    – CascadeVille : Title, NameVille, Descpription

    How to include these two lists ?

    Thanks in advance !! :-)

  2. I have check my code and I confirm, the JQuery libraries are include.
    (Yes you agree, I got the same problem with my wordpress blog, it “delete” the scripts tag)

    How to verify if JQuery take the list information from my Sharepoint Server ??

  3. Hi,

    This post is a little bit outdated, but I just need to know something :
    I’ve done the same on my sharepoint site, and it’s not working, just 2 lists with few columns.
    It’s working with dropdown list, but not with input field…

    Any idea ?

  4. Hi
    Does this work in Sharepoint 2010(I am using SP Foundation 2010). I tried this but it didn’t work, conventional lookup dropdown fils up information just fine.
    Any ideas?
    cheers

Leave a Reply to Marc Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.