SPServices.SPDisplayRelatedInfo format text using completefunc

Nov 11, 2010 at 3:47 PM

I'm using the display related info function and it works great.  However, one of the columns in my related info list is a lookup.  When I display that column using the display related info function the value is displayed as "ID;#value" e.g. "14;#Manager"

So, I am trying to create a function to remove the extra characters (ID;#) added because the source is a lookup column.  I have spent a great deal of time researching with google to figure out how to trim or substring-after but I can't figure it out.  

The column that needs to be modified is column #1 in the display related info table.  I have tried:

$().SPServices.SPDisplayRelatedInfo({	
	columnName: "Job Description Title",
	//relatedWebURL: "",
	relatedList: "{483F1AEF-1B3B-43DA-9392-47980A5523DE}",
	relatedListColumn: "Title",
	relatedColumns: ["Reports_x0020_To_", "Employment_x0020_Status", "Pay_x0020_Grade", "FLSA_x0020_Exemption_x0020_Statu", "Purpose_x0020_of_x0020_this_x002", "Principle_x0020_Accountabilities", "Required_x0020_Technical_x0020_S", "Required_x0020_Behavioral_x0020_", "Minimum_x0020_Education_x0020_Re"],
	displayFormat: "table",
	headerCSSClass: "ms-vh2",
	rowCSSClass: "ms-vb",
	numChars: 0,
	matchType: "Eq",
	//CAMLQuery: "",
	completefunc: formatText,
	debug: true
});

function formatText() {
               $("#showRelated_Job_x0020_Description_x0020_Titl td:nth-child(1)").substringafter("#");
}

Can anyone offer any advice?

Many thanks,

Scott

Coordinator
Nov 12, 2010 at 3:15 AM

Scott:

SPDisplayReleatedInfo ought to be handling the lookup column formatting for you.  If you look at the SPServices code, there's a function called ShowColumn which builds the output. In jquery.SPServices-0.5.7.js, it's on line 2343.

In that function, there's a case for "Lookup", and the output is constructed like this:

    outString = "<a href='" + opt.relatedWebURL + SLASH + dispUrl + 
     "?ID=" + columnValue.substring(0, columnValue.search(";#")) + "&RootFolder=*'>" + 
     columnValue.substring(columnValue.search(";#") + 2) + "</a>";

Given this and your other problem, I wonder if you have a bad version of SPServices or something. You're sure you have the latest version, right? In your other post you show that you are using 0.5.7, but things aren't jiving with what I see on this end.

Or, maybe there's something unique about your Lookup column. Can you explain abit more about how it is set up?

M.

Nov 15, 2010 at 7:13 PM

I've encountered something similar if the columnXML.att("Type") is "LookupMulti"

The current ShowColumn function doesn't have a case for that column type.

Here is how I made it work:

Case "LookupMulti":
	// Get the display form URL for the lookup source list
	var dispUrl;
	$().SPServices({
		operation: "GetFormCollection",
		async: false,
		listName: columnXML.attr("List"),
		completefunc: function (xData, Status) {
			$(xData.responseXML).find("Form").each(function() {
				if($(this).attr("Type") == "DisplayForm") {
					dispUrl = $(this).attr("Url");
					// Stop looking; we're done
					return false;
				}
			});
		}
	});
	var multiValues = columnValue.split(";#")
	var i
	var skip = false
	outString  = ""
	for (i in multiValues) {
		if (skip==false){			//Hack becuase the values and display text are paired
			outString += "<a href='" + opt.relatedWebURL + SLASH + dispUrl +
						 "?ID=" + multiValues[i] + "&RootFolder=*'>" 
			skip =true
		} else {
			outString += multiValues[i] + "</a>" + ",";
			skip =false
		}
	}
	outString=outString.substring(0,outString.length-1)
	break;

 

 

I'm sure there is a more elegant way than my skip method. But I'm new to javascript.

Also, I found that the href returned didn't work for me since I didn't specify the relatedWebURL. It was missing the current site collection name. So I added an option to capture that. And updated the outString line above to the following

outString += "<a href='/sites/" + opt.siteCollectionName + SLASH + dispUrl +
	"?ID=" + multiValues[i] + "&RootFolder=*'>" 

Coordinator
Nov 17, 2010 at 3:37 AM

peterdave:

Thanks for this addition to the library. It's unusual when someone kicks code back in and I (and everyone else who ends up benefitting) certainly appreciates it.

Interestingly, I haven't had anyone else report this issue before, which I suppose surprises me. Clearly I hadn't run across this circumstance in anything I've done in testing or else I would have fixed it. I'll add this to the list for the next release.

Thanks again!

M.

Coordinator
Nov 17, 2010 at 3:37 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.