SPDisplayRelatedInfo not working with matchOnId: true

Feb 28, 2012 at 4:31 AM

I am trying to use SPDisplayRelatedInfo with a Contacts list. The code works fine for matchOnId: false, but  that's not what I need (several people with the same last name). When I switch to matchOnId: true, no information gets returned when I select a contact. Any clue on this? I am using the latest version 1.7.1a.

Thanks!

 

Feb 29, 2012 at 11:51 PM

I'd still be interested to know whether I did something wrong, or what I came across is a bug in SPServices.

In the meantime, I found a fun trick to work around my issue. Instead of SPDisplayRelatedInfo, I am using a combination of SPFilterDropdown without filter and a calculated column to get a similar result. Maybe I should write a blog post about it :-)

Coordinator
Mar 1, 2012 at 12:18 AM

Can you show your code? Have you customized the list at all or is it a vanilla Contacts list?

M.

Mar 1, 2012 at 1:41 AM

It's almost a vanilla Contacts list, I just added a text column called EmployeeID

$().SPServices.SPDisplayRelatedInfo({
 columnName: "Owner",
 relatedWebURL: "",
 relatedList: "Employees",
 relatedListColumn: "Title",
 relatedColumns: ["Title","FirstName","Email","EmployeeID"],
 displayFormat: "table",
 numChars: 0,
 matchType: "Eq",
 CAMLQuery: "",
 matchOnId: true,
 debug: true
});
I am on SharePoint Foundation and I used SPServices 1.7.1a. matchOnId: false worked fine.
Coordinator
Mar 1, 2012 at 5:21 PM

What type of column is Owner? It should be a lookup column into Employees.Title.

M.

Mar 1, 2012 at 10:19 PM

Exactly. On the form, Owner is a lookup to the Employees list. Employees is a Contacts list, and I point to the Last Name field (Title). When I have two people with the same last name, I want to see the related information for the one I picked. If I use matchOnId:false, it returns the related information of all people with the last name I selected.

Coordinator
Mar 1, 2012 at 10:57 PM

I think it's working as built. Before I added the matchOnId option, it would have always returned all of the matches, which was actually what I thought would be cool to see. For instance, all products in a certain product category.

When you set matchOnId, you'll only see the one match because it's an ID to ID match.

Make sense?

M.

Mar 1, 2012 at 11:15 PM

It makes perfect sense and that's exactly what I am looking for. My issue is that it returns no item, not even the one that matches the id.

Coordinator
Mar 1, 2012 at 11:37 PM

Ah, OK. Sorry, I think I misunderstood. Let me set up a test.

M.

Mar 26, 2013 at 6:24 PM
Did anyone get this figured out? I have run into the same issue. Using 'matchOnId: true' causes the function to return 0 items. I believe I have the solution. I'm using SPServices 0.7.1a so if this has already been fixed in later releases, my apologies.

Looking at line ~1739, we're creating a query string as...
    camlQuery += "<Eq><FieldRef Name='" + opt.relatedListColumn +
        (opt.matchOnId ? "' LookupId='True'/><Value Type='Integer'>" : "'/><Value Type='Text'>") +
        escapeColumnValue(columnSelectSelected[0]) + "</Value></Eq>";
When matchOnId = true, I beleive we should be filtering on the ID field of the target list and not the opt.relatedListColumn. So, I modified the source code to look like this....
    camlQuery += "<Eq><FieldRef Name='" +
        (opt.matchOnId ? "ID' /><Value Type='Integer'>" : opt.relatedListColumn + "'/><Value Type='Text'>") +
        escapeColumnValue(columnSelectSelected[0]) + "</Value></Eq>";
I believe this comes up in other places in the code but I haven't gone through it. I wanted to get a second look at my madness before I press on.

Thanks,

Geoff
Coordinator
Mar 26, 2013 at 6:49 PM
Geoff:

It's not a Query String, but filtering in the CAML.

By specifying LookupId='True', we're telling GetListItems to look at the ID of the item, not the text value of it. So if the value is 12;#Monkees, without specifying LookupId='True', it would match all items which had the text "Monkees". With LookupId='True', it'll only match where ID=12, thus exactly one item.

The syntax in JavaScript with the question mark is this:

[condition] ? [true value] : [false value]

It's just a shortcut for if-then-else.

M.
Coordinator
Mar 26, 2013 at 6:52 PM
p.s. I admit that I totally dropped the ball on this thread. However, I haven't had any other reports of issues that I can recall.

M.
Mar 26, 2013 at 6:54 PM
Right, I just realized that and also realized I may be using the function differently than intended. In my case, I’m looking up a Title field and it is a single line of text. It can repeat itself throughout the records in the lookup list but I only want related info on a single particular record. So, my mod works for what I’m doing but will certainly break it if I choose to do the lookup on a “Lookup” type field. Does that make sense?

Geoff
Mar 26, 2013 at 7:05 PM
So, I'm running this function...
    $().SPServices.SPDisplayRelatedInfo({   
        columnName: "Event",
        relatedList: "Calendar",
        relatedListColumn: "Title",
        relatedColumns: ["Title", "EventDate", "EndDate", "Location", "Capacity", "Deadline"],
        matchOnId: true,
        completefunc: updateCapacityCheck
    });
When the function creates the query parameter for the GetListItems call, it looks like....
<Query><Where><Eq><FieldRef Name='Title' LookupId='True'/><Value Type='Integer'>7</Value></Eq></Where></Query>
However, since I'm trying to do a lookup on a title field that is straight text (no in the form '00;#Text'), it returns 0 records. With the way I modified the function, my query paramter looks like...
<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Integer'>7</Value></Eq></Where></Query>
Which returns the record data I'm looking for. However, if I were trying to lookup a Lookup type field in the first place, the original function works.
Coordinator
Mar 26, 2013 at 7:06 PM
I think that your mod has the same effect as my approach. You're swapping column names and I'm swapping access methods.

If you aren't getting what you expect using my code, can you post the SOAP request that is sent with my code and your code in the same instance?

M.
Coordinator
Mar 26, 2013 at 7:07 PM
You beat me to it.

I built the SPDisplayRelatedInfo function only to work with Lookup columns (dropdowns). It sounds like you are trying to use it a different way?

M.
Mar 26, 2013 at 7:20 PM
'Event' is a lookup column. It looks up 'Title' from the list "Calendar." So, it will store data in the form "7:#MyEvent." When I choose matchOnId: false, the query parameter is "MyEvent" and when I choose matchOnId: true, the query parameter is 7. So, that part appears to work for me as designed. However, when SPDisplayRelatedInfo creates the GetListItems call, it constructs the Query option and uses "Title" as the filter field whether it is trying to match on text or an ID. When matchOnId: false, the query correctly looks for "My Event" in the title field. However, when matchOnId: true, it is looking for 7 in the Title field (which it will never find, regardless of "LookupId='True'" because Title isn't a Lookup field.
Coordinator
Mar 26, 2013 at 7:49 PM
As they say around here: "light dawns on Marblehead". I see what you're talking about, and I've got a bug.

Your fix above is right. Fixing...

M.
Coordinator
Mar 26, 2013 at 8:07 PM
It's a little more complicated, of course, but still I'm fixing it.

M.
Coordinator
Mar 26, 2013 at 8:15 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.