Error with SPDisplayRelatedInfo function when relatedListColumn is an ID

Nov 27, 2009 at 4:56 AM

I am having a problem with the SPDisplayRelatedInfo function when the relatedListColumn is an ID. I get the error “Column not found in related list”.

I have a document library Post Attachments with a lookup column PostID related to the ID column in the Posts list.

I am trying to use the code below to display some related info from the Posts list in the Post Attachments edit form.

<script language="javascript" type="text/javascript">
	$(document).ready(function() {
		$().SPServices.SPDisplayRelatedInfo({ 
		columnName:  "PostID",
		relatedList:  "Posts",
		relatedListColumn:  "ID",
		relatedColumns:  ["Title","Published","Category"],
		displayFormat:  "list"
		,debug:true});
	});
</script>

But I receive the error:

Error in function
SPServices.SPDisplayRelatedInfo
Parameter
relatedListColumn: ID
Message
Column not found in relatedList Posts

If I use change the lookup column to Title I don't get the error. The ID column of the Posts list is (obviously) available to select when creating the lookup column, it is also visible in SharePoint designer in the data source details. However, it doesn't appear in the list of columns when viewing the list settings, but is available to be included in views???

Any ideas?

Thanks.

 

Coordinator
Nov 27, 2009 at 5:04 AM
Edited Nov 27, 2009 at 5:50 AM

Joel:

When you switch to Title, do you see any results at all?  For instance, the column name headers? Is the Posts list in the same site as the Post Attachments list? Are the lists in a Blog site? What type of column is PostID?

Sorry for all the questions, but I want to try to reproduce the right thing on my end.

M.

Coordinator
Nov 27, 2009 at 5:51 AM

Joel:

I stumbled across some interesting things as I was trying to reproduce your situation: http://mdasblog.wordpress.com/2009/11/27/interesting-new-use-for-spdisplayrelatedinfo/.  I want to solve your problem, of course, but that was fun!

M.

Nov 27, 2009 at 6:05 AM

Hi Mark,

If I switch to Title it all works perfectly, column name headers, column values are all displayed.

Yes, the Posts lists is in the same site.

Yes, the lists are in a blog site.

PostID is a lookup column to ID in the Posts list. Since ID does not appear in the columns under list settings, I can't (unequivocally) say what column type it is???

The autocomplete is great! Just need to update the CSS and hook some jQuery to allow the user to select from the suggestions and populate the text box. sweet.

 

Coordinator
Nov 27, 2009 at 2:50 PM

So are you still having an issue or are you all set? If PostID is a Lookup column, then are you selecting from a dropdown? IDs are numbers, but in CAML you generally refer to them as Counter.

I've thought of some nice little enhancements to SPDisplayRelatedInfo due to this little exercise!

M.

Nov 28, 2009 at 2:40 AM

Still having the problem if the lookup column is based on ID.

Yes, selecting from a dropdown.

When viewing a blog post I am showing any related attachments in a dataview based on the Post ID passed in the query string.

To add an attachment, I tried passing the Post ID in the query string and pre-populating the form value. Unfortunately the upload form fires first and is in the _layout directory, so I couldn't readily customise it. Uploading the document and selecting the ID from the lookup is a little clunky, co I thought I could use the SPDisplayRelatedInfo function to display something more useful to the users. Perhaps I should just use the title for the lookup and in the queryu string.

Thanks for your help with this.

Coordinator
Nov 28, 2009 at 4:47 AM

I'm still a little fuzzy on what you're doing, but you should be able to pass the PostID in the Query String through upload.aspx, and then populate the EditForm.aspx with it.

M.

Nov 30, 2009 at 6:01 AM

Thanks Mark,

With your prompting I was able to pass the PostID in the querystring, not sure what I was doing wrong previously.

Thanks again.

Coordinator
Nov 30, 2009 at 1:19 PM

Glad you got it working! Let me know if there's anything else you need help with.

M.

Dec 1, 2009 at 8:55 AM
Edited Dec 1, 2009 at 12:29 PM

Hello,

This is my problem post on your blog :

http://mdasblog.wordpress.com/2009/11/27/interesting-new-use-for-spdisplayrelatedinfo/

And I almost resolve it thanks to you !!

This is my code that runs perflectly :

 

<script language="javascript" type="text/javascript" src="http://ardenne-informatique.com/~nekrofage/jquery/jquery-1.3.2.min.js"></script>
<script language="javascript" type="text/javascript" src="http://ardenne-informatique.com/~nekrofage/jquery/jquery.SPServices-0.4.5.min.js"></script>

<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $().SPServices.SPDisplayRelatedInfo({
        columnName:  "IdVille",
        relatedList:  "CascadeVilles",
        relatedListColumn:  "idville",
        relatedColumns:  ["idville", "Title", "Numero"],
        displayFormat:  "table"
        ,debug:true});
    });
</script>

/>

IdVille and idville must be in number column type.

It display only one item that begin "11" by example not all (111, 112, 1123, etc.)

Does it possible to change the display name of the related list :

idville -> Num ville

Title -> Titre

Numero -> Numéro

Ps : Excuse me for my bad english... :-(

Coordinator
Dec 1, 2009 at 12:38 PM
Edited Dec 1, 2009 at 12:39 PM

Glad you've gotten it to work.

The column headers simply come from the DisplayNames of the columns in the relatedList.  So if you want to change the headers displayed by SPDisplayRelatedInfo, you'd change the DisplayName of the column there.  If that's not possible (for whatever reason), you *could* change the headers using jQuery on the form. Something like this:

$(".ms-vh2:contains('idville')").html("Num ville");

M.

Dec 1, 2009 at 3:37 PM
sympmarc wrote:t possible (for whatever reason), you *could* change the headers using jQuery on the form. Something like this:

$(".ms-vh2:contains('idville')").html("Num ville");

It's run !! :-)

I use your code like this :

$("th.ms-vh2:contains('idville')").html("Num ville");

  Add before the last  });

Coordinator
Dec 1, 2009 at 4:55 PM

Great!

M.

Dec 7, 2009 at 11:08 AM

Hello !

I got 2 questions :

- Does it possible to hidden the fieldname in the table mode ?

By example : "ID", Title", etc.

- Does it possible place the SPDisplayRelatedInfo on the right of the drop-down menu not under ??

Thanks in advance for your answer !! :-)

Coordinator
Dec 7, 2009 at 12:51 PM

LeSanglier:

There's a tip in the documentation for hiding the column headers: 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.)

Right now, I only offer the two formats for output: "table" and "list".  However, in the lastest v0.4.7ALPHA (http://spservices.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=36650) I've added a completefunc to several of the functions.  You could add some jQuery there to rearrange the output.  If you think that what you want to do would be of general use, sketch it out a little more fully for me and I may add it as a third format alternative.

M.

Dec 7, 2009 at 1:09 PM
LeSanglier wrote:

Hello !

I got 2 questions :

- Does it possible to hidden the fieldname in the table mode ?

Hello

It's possible, check here: Few Extensions.

You can use $.fn.SPServices.SPDisplayRelatedInfoEx function with parameter displayFormat set to "tableOnlyBody".

- Does it possible place the SPDisplayRelatedInfo on the right of the drop-down menu not under ??

Your second question: it's probably not possible, because of the default SharePoint css. But you could try assigning a new css class to the new DIV and defining that class in the CSS file.

About your question:

LeSanglier wrote:

Does it possible to change the display name of the related list :

idville -> Num ville

Title -> Titre

Numero -> Numéro

Adding a new parameter "relatedColumnDisplayName" would be a nice feature.
It would determine the displayed title of the column. If the parameter was empty or it's length was different than relatedColumns' array length, then the title of the column would be determined as now.

J.

Coordinator
Dec 7, 2009 at 1:25 PM

J.:

Nice to see the community working together on this! Thanks for chipping in.

BTW, I haven't forgotten about your extensions.  I need to go through them in some detail to see where I might appliy them. As you may have noticed, I did a pretty major refactoring of the code in some of the functions in v0.4.5, so I need to see where application of your ideas would make the most sense.

M.