«

»

Nov 27 2009

Print this Post

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).

Permanent link to this article: http://sympmarc.com/2009/11/27/interesting-new-use-for-spdisplayrelatedinfo/

6 comments

1 ping

  1. LeSanglier

    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 !! :-)

    1. Marc

      The issue is probably that you haven’t included references to the two jQuery libraries or the script tags (at least in what I see that you’ve pasted into your comment; sometimes WordPress cuts things out). Take a look at the bottom of this page: http://spservices.codeplex.com/documentation for an example.

      M.

  2. LeSanglier

    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 ??

    1. Marc

      I had one other report that there was an issue with SPDisplayRelatedInfo when the ID was the matching column, but I haven’t reproduced it. What type of column is IdVille?

      Let’s move this discussion over to the Codeplex site so that we can easily share code: http://spservices.codeplex.com/Thread/List.aspx

      Thanks,
      M.

  3. jderoubaix

    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 ?

    1. Marc

      jderoubaix:

      I’m going to attempt to answer this on your post over on the SPServices Codeplex site.

      M.

  1. Interesting New Uses for SPDisplayRelatedInfo: Follow Up « Marc D Anderson's Blog

    [...] } Following up on my post Interesting New Uses for SPDisplayRelatedInfo, I’ve just added two new options to the SPDisplayRelatedInfo function in the first alpha for [...]

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>