Open SharePoint List/Library Link in New Window

Why can’t a SharePoint list/library web part open links in a new window by default?

Right… maybe someday.

There are several workarounds, but here’s one of the “easy” ones that seems to make sense to site owners. It adds some Javascript in an XML Web Part or Form Web Part that’s placed below the list/library web part (maybe, even at the bottom-most zone on the page, no?). Why not use a Content Editor Web Part for the script? Well, it was a fine place to put the script in SP2007, but to survive a migration from SP2007 to SP2010, the XML Web Part seems to be the way to go for small scripts like this, and if already in SP2010, the Form Web Part should do the trick.

The code looks for the name of the list/library on page load and adds the “target” attribute to the list web part’s table tag. So, say the list name in the current site is called “Links.” The code would look for that list name in the page source by it’s Summary attribute:

<script language="javascript" type="text/javascript">
	var tbl = document.getElementsByTagName('table');
		for(var i = 0; i < tbl.length; i++)
		{
		if(tbl[i].getAttribute("Summary") == "Links")
		{
			var anc = tbl[i].getElementsByTagName('a');
			for(var j = 0; j < anc.length; j++)
			{
				anc[j].setAttribute('target', '_blank');
			}
		}
	}
</script>

For more than one list/library on the page, the code is a bit different…

<script language="javascript" type="text/javascript">
	var tbl = document.getElementsByTagName('table');
	for(var i = 0; i < tbl.length; i++)
	{
	if(tbl[i].getAttribute("Summary") == "Links1" 
	|| tbl[i].getAttribute("Summary") == "Links2"
	|| tbl[i].getAttribute("Summary") == "Links3"
	)
		{
		var anc = tbl[i].getElementsByTagName('a');
		for(var j = 0; j < anc.length; j++)
			{
			anc[j].setAttribute('target', '_blank');
			}
		}
	}
</script>

Advertisements

Calculated Columns for Cascading Drop-Downs in SharePoint Lists and Libraries

Situation
SharePoint list or library users need a simple way to enter data in one column that depends on what was entered in another, but out-of-the-box SharePoint 2007 or 2010 does not support direct cascading functionality. Using jQuery for SharePoint Web Services might be an option for cascading drop-downs, but you are not allowed to use SharePoint Designer to modify the EditForm, and besides, you want the behavior to work inside the list/library itself in datasheet view and not just in the EditForm. Lookup columns could do the trick, but let’s say you’re already at the farm-wide threshold setting of eight per list/library.┬áManaged Metadata in the Term Store perhaps? But, the terms are not universal and getting a few simple entries requires more than a few clicks.

Opportunity
If there are only a few fields that relate to one another, one straightforward option might be to create a Choice column that allows users to select a delimited text string that contains all of the relationships in a single line, and then use Calculated Columns to parse the string out into separate columns.

Actions
For example, a Choice column called “Section – Category” could delimit a drop-down menu of sections and categories with a semi-colon character, making it pretty easy for people to spot the combo they’re looking for:

1 – Pre-Visit; 1 – Charting
1 – Pre-Visit; 2 – Phone Calls / Messaging
1 – Pre-Visit; 3 – Registration
1 – Pre-Visit; 4 – Scheduling
2 – Patient Visit; 5 – Check-in
2 – Patient Visit; 6 – Chronic Care / Education
2 – Patient Visit; 7 – MyChart
2 – Patient Visit; 8 – Orders / Charting
2 – Patient Visit; 9 – Rooming
3 – Post-Visit; 10 – Charting
3 – Post-Visit; 11 – Orders
3 – Post-Visit; 12 – Phone Calls / Messaging
4 – Bars; 13 – Between Visits
4 – Bars; 14 – Daily Work & General

One calculated column called “Section” and another called “Category” could contain formulas that split the string into left and right contents. But let’s take it up a notch and turn the string into four columns – “SectionID”, SectionTitle”, CategoryID”, and “CategoryTitle.” See where this is going?

SectionID – the formula is pretty basic, but it’s not just getting the first character from the left in the string, because the number might end up with more than one character. It’s about getting everything to the left of the first space ” ” character. Now, note this dash has spaces around it. This is important visually for users, but it also serves to make it different than any hyphens used in the words. So, after finding the ” – ” character, the space needs to be subtracted with a “-1” thusly:

=LEFT([Section - Category],FIND(" ",[Section - Category])-1)

SectionTitle – here the formula starts getting a bit more complex. We want the words to the left of the “;” and to the right of the ” – “. Note the use of “-1” here too to remove spaces around the dash, and also note that there is a space on the right of the dash in “- “:

=RIGHT(LEFT([Section - Category],FIND(";",[Section - Category])-1),LEN(LEFT([Section - Category],FIND(";",[Section - Category])-1))-FIND("- ",LEFT([Section - Category],FIND(";",[Section - Category])-1))-1)

CategoryID – same fun, but now wanting all the numbers from the string on the right of the “;” that are left of the ” – ” on the right hand string:

=LEFT(RIGHT([Section - Category],LEN([Section - Category])-FIND(";",[Section - Category])-1),FIND(" -",RIGHT([Section - Category],LEN([Section - Category])-FIND(";",[Section - Category])-1))-1)

CategoryTitle – not as simple as it looks, this task is to get all the words from the right side of the “;” and the right side of the ” – ” that’s in the right side string;

=RIGHT(RIGHT([Section - Category],LEN([Section - Category])-FIND(";",[Section - Category])),LEN(RIGHT([Section - Category],LEN([Section - Category])-FIND(";",[Section - Category])))-FIND("- ",RIGHT([Section - Category],LEN([Section - Category])-FIND(";",[Section - Category])))-1)

Results
Selecting a single item in the Choice column like “1 – Pre-Visit; 1 – Charting” yields:

SectionId SectionTitle CategoryId CategoryTitle
1 Pre-Visit 1 Charting

This method of creating cascading drop-down columns can work well as long as the choices are simple – meaning limited to two to three columns. The formulas can get as complex as your brain can comprehend, and calculation speed does not seem to be an issue.