1/03/2011

Cincinnati SharePoint User Group January Meeting

 

http://www.cincinnatispug.org/

 

First meeting of the new year for the Cincinnati SharePoint User Group is Thursday January 6th, 2011.

And if you are in the Dayton area, don’t forget the DAYSPUG meeting on Tuesday January 11th!

 

 

January's Presentation

SharePoint 2010 and Business Intelligence

You’ve got data, probably lots and lots of data across multiple systems. Your end users however want timely access to information to make effective decisions and to monitor and analyze performance. Join us for a high level overview and demonstration of what SharePoint 2010 has to offer end users who have Business Intelligence needs. Topics covered will be:

  • Excel Services
  • PowerPivot
  • Visio Services
  • Reporting Services (SharePoint Integrated Mode)
  • Performance Point Dashboards

 

Presenter: Tavis Lovell


Tavis Lovell is a Practice consultant with Ascendum Solutions, specializing in SQL Server (Integration Services, Reporting Services, Analysis Services) and database design related to transactional or BI implementations on the Microsoft stack. Tavis is also involved with using SharePoint 2010 for content delivery as it relates to Business Intelligence. When he’s not trying to help the world make better decisions, he spends his time either pretending he’s Jimi Hendrix, or falling down the sides of mountains on a snowboard

 

.

12/31/2010

Book Review: SharePoint 2010 How-To

 

I have not written a book review in a while, and as the Cincinnati SharePoint User Group got a stack of these to give away as door prizes, I figure it’s about time. Besides, I need to give this last copy away at January’s meeting.

SharePoint 2010 How-To is written by Ishai Sagi, a SharePoint trainer, solution developer and a SharePoint MVP from Australia. The book is just shy of 400 pages and contains “how-tos” for just about every SharePoint 2010 end-user and site owner feature. This is not so much a tutorial where you will sit down and read it from cover to cover, but more of a quick reference guide useful to both “team members” and site owners.

I even learned something new! How to use SharePoint 2010 tagging on external web sites. See page 56.

I recommend this book as a quick reference guide for both self taught users and for those who have taken a SharePoint Power User / Site Owner class.

Amazon has the book for $25.54, and the Kindle Edition for only $15.39, so you can afford one for each of your SharePoint site owners.

The paperback edition: The Kindle edition:
                

12/30/2010

Books and Resources for SharePoint Branding

 

This is a resource page for folks who attend my classes, and for a book I am working on. Please let me know of good resources for SharePoint branding.

 

Books

 

(I have not reviewed these books… yet. If the authors or the publisher would like to send me a copy… hint, hint.)

 

 

While not focused on branding, you may also want to consider my book on SharePoint Customization for Site Owners (coming very soon now.

 

Blogs and Web Sites

 

The premier site for everything about SharePoint 2007 branding:

http://www.heathersolomon.com/blog/

 

Randy Driscall’s blog  (author of books above)

http://blog.drisgill.com/

 

All kinds of SharePoint resources:

http://www.codeplex.com  (and then search for “SharePoint” or “SharePoint Branding”)

 

An interesting article for developers: Automated SharePoint Site Branding

http://msdn.microsoft.com/en-us/magazine/cc700347.aspx

 

Real World Branding with SharePoint 2010 Publishing Sites

http://msdn.microsoft.com/en-us/library/gg430141.aspx

 

Branding Office SharePoint Server 2007

http://blogs.msdn.com/b/brianwilson/archive/2008/07/13/branding-office-sharepoint-server-2007.aspx

 

SharePoint 2010 Branding

http://blogs.captechconsulting.com/blog/donavan-marais/sharepoint-2010-branding

.

12/29/2010

SharePoint: Convert a Links list to a Dropdown list (updated!)

 

This is an updated version of an older blog article. The updates include support for both SharePoint 2007 and 2010 and for better multiple browser support.

Updated again to include a Content Query Web Part (CQWP) example.

 

Problem: There is never enough room on your SharePoint home page. So what do you do if you have a long list of vendor links you would like to display on the home page. You would usually use a Links list and add a Links list web part. But it takes up too much space. How about a simple dropdown list?

   image

 

Solution: Yet another Content Editor Web Part (CEWP) trick!  A CEWP and some JavaScript…

   image

                   image

Steps:

  1. Create your links list and add your links
  2. Add the link list’s web part to the page
  3. Add a Content Editor Web Part (CEWP) to the page just under the links list web part
  4. Modify the CEWP and set its title (or set its Chrome to none to hide the title)
  5. Click Source Editor and then copy and paste the HTML and JavaScript from below
  6. Edit the JavaScript to change the word “Links” to the name of your links list web part (title of the web part, not the title of the actual list, although they may be the same)
    if (x[i].summary == "Links") to
    if (x[i].summary == "Your Links List Title")
    The best way to confirm this name is to right-click the web part page and search for "summary=" and copy and paste the name
  7. Exit the edit mode and test it

 

The Code:

<!-- the dropdown list for the link items -->
<select name="JumpToList" id="JumpToList"
    onchange="javascript:JumpToUrl(JumpToList.options[JumpToList.selectedIndex].value)">
  <option>Jump to ...</option>
</select>

<script>
// CEWP trick from techtrainingnotes.blogspot.com! 

var linksListSummaryName = "Links Use the … (your list summary name here!) …"

function JumpToUrl(url)
{
    location.href = url;
}

//code to hide the links list and populate the select list

//Find the link list and hide it
var x = document.getElementsByTagName("TABLE") // find all of the Tables 
var LinkList;
var i=0;
for ( i=0; i<x.length; i++ ) 
{
  if (x[i].summary == linksListSummaryName)
  {
    //
    LinkList = x[i];

    //hide the links list web part (tables in tables in tables ...)
    // Note: while testing, you may want to comment out the next line
    x[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
    break;
   } 
}

if (LinkList)
{
  //Copy all of the links from the link list to the select list
  var ToList = document.getElementById("JumpToList");

  var links = LinkList.getElementsByTagName("A"); // find all of the links
  for ( i=0; i<links.length; i++ ) 
  {
    if (links[i].onfocus)
    {
      if (links[i].onfocus.toString().indexOf("OnLink(this)") > -1)
        { ToList.options[ToList.length] = new Option(links[i].innerHTML, links[i].href); }
    }
  }
}
else
{
  alert("Link list named '" + linksListSummaryName + "' not found")
}
</script>

 

Want to add a new “Add New Link” link?

Add the following just after the </select> tag in the code above (your the URL to your list!).

<br>
<a href="http://yourserver/sites/yoursite/Lists/Links/NewForm.aspx">Add new link</a>

 

Dropdown list for a Content Query Web Part.

While the approach is similar to a links list, the HTML generated by a CQWP is a bit different. Below is the code for a CQWP.

Steps:

  1. Create your CQWP
  2. Add the CQWP to the page
  3. Optional: Modify the CQWP and set it’s Chrome to none
  4. Add a Content Editor Web Part (CEWP) to the page just under the CQWP
  5. Modify the CEWP and set its title (or set its Chrome to none to hide the title)
  6. Click Source Editor and then copy and paste the HTML and JavaScript from below (note that there is a 2007 and a 2010 version)
  7. Edit the JavaScript to change the “linksListSummaryName = ” value to the name of your CQWP (view the source of the page and search for the web part’s name) 
  8. Exit the edit mode and test it

 

The Code – 2007 version:

<!-- the dropdown list for the link items -->
<select name="JumpToList" id="JumpToList"
    onchange="javascript:JumpToUrl(JumpToList.options[JumpToList.selectedIndex].value)">
  <option>Jump to ...</option>
</select>

<script>
// CEWP trick from techtrainingnotes.blogspot.com! 
// for a CQWP


// copy the following from the "<td title="Content Query Web Part - ..."  line in the page's HTML
var linksListSummaryName = "Content Query Web Part - Use to display a dynamic view of content from your site on a web page"

function JumpToUrl(url)
{
    location.href = url;
}

//code to hide the links list and populate the select list

//Find the link list and hide it
var x = document.getElementsByTagName("TABLE") // find all of the Tables 
var LinkList;
var i=0;
for ( i=0; i<x.length; i++ ) 
{
  if (x[i].childNodes[0].childNodes[0].childNodes[0].title == linksListSummaryName)
  {
    LinkList = x[i].parentNode.parentNode.nextSibling;

    //hide the links list web part (tables in tables in tables ...)
    // Note: while testing, you may want to comment out the next line
    x[i].parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
    break;
   } 
}

if (LinkList)
{
  //Copy all of the links from the link list to the select list
  var ToList = document.getElementById("JumpToList");

  var links = LinkList.getElementsByTagName("A"); // find all of the links
  for ( i=0; i<links.length; i++ ) 
  {

    if (links[i].href.indexOf("CopyUtil.aspx")>0)
    {
      ToList.options[ToList.length] = new Option(links[i].innerHTML, links[i].href);
    }
  }
}
else
{
  alert("Link list named '" + linksListSummaryName + "' not found")
}
</script>

 

The Code – 2010 version:

<script>
// CEWP trick from techtrainingnotes.blogspot.com! 
// for a CQWP


// copy the following from the "<td title="Content Query Web Part - ..."  line in the page's HTML
var linksListSummaryName = "Content Query - Displays a dynamic view of content from your site."

function JumpToUrl(url)
{
    location.href = url;
}

//code to hide the links list and populate the select list

//Find the CQEW and hide it
var x = document.getElementsByTagName("TD") // find all of the Tables 
var LinkList;
var i=0;
for ( i=0; i<x.length; i++ ) 
{
  if (x[i].title == linksListSummaryName)
  {
    LinkList = x[i].parentNode.parentNode.parentNode.parentNode.parentNode.nextSibling;

    //hide the links list web part (tables in tables in tables ...)
    // Note: while testing, you may want to comment out the next line
    x[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
    break;
   } 
}

if (LinkList)
{
  //Copy all of the links from the link list to the select list
  var ToList = document.getElementById("JumpToList");

  var links = LinkList.getElementsByTagName("A"); // find all of the links
  for ( i=0; i<links.length; i++ ) 
  {

    if (links[i].href.indexOf("CopyUtil.aspx")>0)
    {
      ToList.options[ToList.length] = new Option(links[i].innerHTML, links[i].href);
    }
  }
}
else
{
  alert("Link list named '" + linksListSummaryName + "' not found")
}
</script>

.

12/28/2010

SharePoint: How to truncate a Multiline column and add a “More” link to the DispForm.aspx page to display the full text

 

The following is a quick solution to a little problem. It works for the lists I’ve tested with. Your results may vary… ;-) 

Before you read further:

  • It does not work with the Links List
  • This might not work with 2010 with the AJAX “Enable Asynchronous Load” checked (but it has worked with my limited testing)

 

The Goal:

  • Truncate a Multiline column to “xx” characters
  • Add a “More” link to send the user to the DispForm.aspx page to display the full text

A picture is worth a thousand words, so here’s two thousand worth…

The list before any edits:

   image

 

The goal:

   image

 

We want to take the text from a long multiline text column and truncate it to say 50 characters and then add a “More” link to take the user to the DispForm.aspx page so they can read all of the text. The JavaScript below is similar to many of the JavaScript “hacks” that I have posted before. It first searches for an HTML table with an attribute named “summary” that contains the name of the list. It then looks inside of this table for TR tags to find the rows. We then filter to only rows containing more than 2 TD tags. We then extract the HREF (URL) to the DispForm.aspx page that’s in the default link for the list item. Next we extract the long text from the text column (TD), shorten it to “xx” characters, append the “More” link using the HREF found earlier and then write this back into the DIV in the TD.

 

Steps:

Note: These steps show adding a Content Editor Web Part to hold the JavaScript. You can also edit the page in SharePoint Designer and add the code below just before then end tag of the PlaceHolderMain block.

  1. Go to the page with the list displayed as a web part and click Site Actions, Edit Page
     
  2. Add a Content Editor Web Part and move it below the list’s web part
     
  3. For SharePoint 2007:
      - Edit the web part, click the Source Editor button and paste the JavaScript code from below
      - Edit the five variables (see notes below) 

    For SharePoint 2007 or 2010:
      - Copy the JavaScript code from below and paste into Windows Notepad
      - Edit the five variables (see notes below) 
      - Save or upload the file to a SharePoint library
      - Copy the URL for the file in the library (right-click the file and click Properties)
      - Return to your web part page, edit the Content Editor Web Part and paste the URL into the Content Link box
     
  4. Test

 

The code:

 

You must change the following variables:

  • var SummaryName – Make sure this is correct! The best way to get the correct text is to right-click on the page with the list web part and select View Source. Do a search for “summary=” and copy the name. SharePoint 2010 may add a space at the end of the summary name. Don’t delete this! Both versions will include the web part name and the list description as part of the “summary=”
  • var ColumnWithDropDown and var ColumnWithLongText – Remember, the first column is #0 and the second is #1…
  • var CharactersToShow – Just what it’s name implies… If the column as fewer than this many characters, then there is no change, but if more, then the column is truncated and a “More” link is added.
  • var isEnhancedRichText – If the column is Enhanced Rich Text then the HTML is a bit different.
<script>
// CEWP trick from techtrainingnotes.blogspot.com!
// techtrainingnotes.blogspot.com/2010/12/sharepoint-how-to-truncate-multiline.html // Update the next five variables to match your list var SummaryName = "Tasks Use the Tasks list to keep track of work that you or your team needs to complete." ; var ColumnWithDropDown = 2; //first column is 0 var ColumnWithLongText = 8; var CharactersToShow = 100; var isEnhancedRichText = false; var tables = document.getElementsByTagName("TABLE"); for (var i=0;i<tables.length;i++) { if ( tables[i].summary == SummaryName ) { var rows = tables[i].getElementsByTagName("TR"); for (var j=1;j<rows.length;j++) { if (rows[j].childNodes.length > 2) { if ( rows[j].childNodes[ColumnWithDropDown ] == "[object Text]") continue; // fix for FireFox var href = rows[j].childNodes[ColumnWithDropDown ].getElementsByTagName("A")[0].href if (href.toLowerCase().indexOf("dispform.aspx") == -1 && href.toLowerCase().indexOf("listid=") == -1 ) { var docID = rows[j].childNodes[ColumnWithDropDown].childNodes[0].id // if not "dispform.aspx" then must be a library or links list // if "listid=" then must be a task list in 2010 var parts = href.split("/"); parts[parts.length-1] = "forms/DispForm.aspx?ID=" + docID; href = parts.join("/"); } var theNode; if (isEnhancedRichText) { theNode = rows[j].childNodes[ColumnWithLongText].childNodes[0].childNodes[0]; } else { theNode = rows[j].childNodes[ColumnWithLongText].childNodes[0]; } if (theNode.innerHTML.length>CharactersToShow) { if (document.all) // IE theNode.innerHTML = theNode.innerText.substring(0,CharactersToShow) + "... <a href='" + href + "'><i>More</i></a>" else // FireFox try { theNode.innerHTML = theNode.textContent.substring(0,CharactersToShow) + "... <a href='" + href + "'><i>More</i></a>" } catch (e) {} } } } break; // no need to check the other tables } } </script>

Code Notes:

  • theNode.innerHTML = theNode.innerText… – This strips out all of the HTML formatting from the text and loads back the clear text and the MORE link
  • if ( rows[j].childNodes[ColumnWithDropDown ] == "[object Text]")
    FireFox and ID handle white space differently.
  • theNode.innerText vs. theNode.textContent – IE and FireFox don’t work the same (so what’s new…)

 

 

 

This has been tested on a handful of list types in SharePoint 2007 and 2010. If you had to adjust the code for one of your lists, then please post a few notes for other readers. 

 

.

12/20/2010

Visual Studio 2008 Extensions for Windows SharePoint Services 3.0, v1.3

 

I was starting to wonder if VSeWSS 1.3 CTP (Community Technology Preview) was ever going to get out of “preview” mode, especially now as SharePoint 2010 is here. It’s now officially released! (12/16/2010)

 

See more here on Paul Andrew’s blog (Microsoft Technical Product Manager for the SharePoint Developer Platform):

http://blogs.msdn.com/b/pandrew/archive/2010/12/20/visual-studio-2008-extensions-for-windows-sharepoint-services-vsewss-v1-3-released.aspx

 

Download from here:

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d87523da-b5bc-4296-be8a-8e3785c8f181

 

And while you are browsing Paul Andrew’s blog, also check out the new release for SPDisposeCheck:

http://blogs.msdn.com/b/pandrew/archive/2010/12/13/new-spdisposecheck-release-available.aspx

 

.

12/19/2010

SharePoint: PowerShell Script to List All Users in All Groups

 

 

Here's a quick little PowerShell script to list all groups and all users. Note that if an AD group is listed as a user, all the users in that group may not show up in this list until the user has visited SharePoint at least once.

 

For both SharePoint 2007 or 2010 in any PowerShell:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$site = New-Object Microsoft.SharePoint.SPSite("http://yourservername/sites/yoursitecollection ")

$groups = $site.RootWeb.sitegroups

foreach ($grp in $groups) {"Group: " + $grp.name; foreach ($user in $grp.users) {"  User: " + $user.name} }

$site.Dispose()

 

or for SharePoint 2010 in the SharePoint 2010 Management Shell:

$site = Get-SPSite http://yourservername/sites/yoursitecollection 

$groups = $site.RootWeb.sitegroups

foreach ($grp in $groups) {"Group: " + $grp.name; foreach ($user in $grp.users) {"  User: " + $user.name} }

$site.Dispose()

 

.

12/17/2010

Content by Tag

.

SharePoint: Opening a 2010 Dialog Box from Quick Launch

 

Here’s how to open any page in a SharePoint 2010 popup dialog box from Quick Launch or anywhere else using JavaScript. The key code is from an MSDN article here, but it needed just a little tweaking to work from Quick Launch or an “<A>” tag’s HREF.

 

As a teaser… here’s this site displayed in a SharePoint 2010 dialog box:

image

 

The Code

The MSDN article had this JavaScript example:

var options = SP.UI.$create_DialogOptions();
options.url = url;
options.height = 300;
SP.UI.ModalDialog.showModalDialog(options);

I just needed to modify it so it would work in an HREF of an <A> hyperlink tag. Basically it needed to be in one line and return VOID when called. The following must be typed as all one line!

JavaScript:var options=SP.UI.$create_DialogOptions();
options.url='http://techtrainingnotes.blogspot.com';
options.height = 400;
void(SP.UI.ModalDialog.showModalDialog(options))

 

Now to use it in Quick Launch:

Just go to Site Actions, Site Settings and click Quick Launch. Then click New Navigation Link and add the JavaScript:

image

 

What kind of pages make sense for a dialog box?

It probably does not make much sense to use dialog boxes to display external sites like this one, although it’s better than a Page Viewer Web Part. A better use would be to display any SharePoint page or list/library view and an external report that fits in a popup window.

If you want to display a SharePoint page inside of a dialog box add “?IsDlg=1” to the page’s URL.

Here’s the a normal Shared Documents library page:

image

 

Here’s the same page with “?IsDlg=1” added to the URL:

           http://yourserver/sites/yoursite/Shared%20Documents/Forms/AllItems.aspx?IsDlg=1

image

 

So here’s Shared Documents in a dialog box… notice that you have the ribbon, but not the rest of the master page clutter!

image

 

And as a additional bonus, dialog boxes can be called from within dialog boxes. Here’s the Upload Multiple dialog box being used from the example above:

image

 

Or open a dialog box from a HyperLink

To use in an <A> hyperlink tag:  (again, this is all one line!)

<a
href="JavaScript:var options=SP.UI.$create_DialogOptions();
options.url='http://techtrainingnotes.blogspot.com';
options.height = 400;
void(SP.UI.ModalDialog.showModalDialog(options))"
>
Click here!
</a>

 

Links:

How to: Display a Page as a Modal Dialog Box

http://msdn.microsoft.com/en-us/library/ff798390.aspx

 

How to use JavaScript in Quick Launch

http://techtrainingnotes.blogspot.com/2010/10/sharepoint-javascript-in-quick-launch.html

 

More about the SharePoint JavaScript API

http://msdn.microsoft.com/en-us/library/ee538253.aspx

 

.

SharePoint: Modifying the “Respond to this Survey” Prompt

 

I had a recent request to change a survey’s “Respond to this Survey” text. Here’s two ways to do it, plus the “detective work” on how to do these kinds of changes.

 

If you just want the JavaScript solution then go ahead and scroll down to the end.

 

Solution 1: Don’t change it!

If your goal is to give the user a better way to start a survey, then just give them a direct link from Quick Launch, an Announcement or even an email. The “Respond to this Survey” button is just a link to the “Newform.aspx” for the survey and all you need to do is copy it. Here’s what the links look like:

SharePoint 2007 link:

  http://yourserver/sites/yoursite/Lists/Survey%201/NewForm.aspx?Source=http%3A%2F%2Fyourserver%2Fsites%2Fyoursite%2FLists%2FSurvey%25201%2Foverview%2Easpx

SharePoint 2010 link:

  http://yourserver/sites/yoursite/Lists/Test%20Survey/NewForm.aspx?IsDlg=1

 

Both of these give some interesting hints as to cool things you can do with these links:

  • Redirect to another page on completion: In both 2007 and 2010 you can add “?Source=” and specify a page to go to after the survey has been completed. The destination (Source) could be the survey home page, the site’s home page or a custom “Thank you” page.
     
  • Open the survey in a in a popup dialog box:  In SharePoint 2010 you can add “?IsDlg=1” to the URL to open the survey formatted for a dialog box (more info below). Without this, the survey will be displayed as a normal SharePoint page.
     
  • Note: You cannot use both “Source=” and “IsDlg” in the same URL as the user will just be redirected to a blank page.

To discover these links, just go to your survey and click “Respond to this Survey”. In SharePoint 2007 just copy the URL at the top of the browser. In SharePoint 2010, right-click inside of the dialog box and click Properties. From there you can copy the URL.

Now go to Quick Launch (Site Actions, Site Settings), a new Announcement, a new email, etc and paste the URL.

 

Adding to Quick Launch:

Here’s an example of using the link in Quick Launch. In the following example the URL will send them back to the home page after the survey has been completed:

http://yourserver/sites/yoursite/Lists/Survey%201/NewForm.aspx?Source=http://yourserver/sites/yoursite

image

As displayed in Quick Launch:

image

SharePoint 2010 and “IsDlg=1”

“IsDlg=1” alone is not enough to open a popup dialog box. “IsDlg=1” actually is an instruction to hide the master page content!  So if you want to display just the survey and only the survey, add “IsDlg=1” to the URL.

Without “IsDlg=1”

image

With “IsDlg=1”   (no Title, ribbon, Quick Launch, etc)

image

I’ll add an item to my “Blog To-Do” on show to actually display a page in a dialog box. (or you can just google/bing it!)

 

 

Solution 2: Change the “Respond to this Survey” text

Now for some detective work… Go to your survey page (overview.aspx). Right-click the page and select your browser’s “View Source” option. Search the displayed text for “Respond to this Survey”.

SharePoint 2010:  (I replaced parts of the JavaScript with “…”)

<a
id="ctl00_m_g_e2a6c7f0_8d5e_46a4_985f_8d175bfc5b24_ctl01_ctl00_toolBarTbl_RptControls_ctl00_diidIONewItem" 
accesskey="N" title="Respond to this Survey" 
onclick="javascript:NewItem2(event, ' ... ');return false;" 
href="javascript:__doPostBack('  ...  ','');">
  <img align='absmiddle' alt="Respond to this Survey" 
           src="/_layouts/images/NewItem.gif" style='border-width:0px;' />
   &#160;
  <span class="ms-splinkbutton-text">Respond to this Survey</span>
</a>

SharePoint 2007:

<a id="ctl00_m_g_bcf319ff_0b26_4f28_b8d3_70cbf4e8152a_ctl00_ctl00_toolBarTbl_RptControls_ctl00_diidIONewItem" 
accesskey="N" title="Respond to this Survey" 
onclick="javascript:NewItem(' ... ');return false;" 
href="javascript:__doPostBack(' ... ','');">
<img align='absmiddle' alt="Respond to this Survey" 
         src="/_layouts/images/NewItem.gif" style='border-width:0px;'>
  &nbsp;Respond to this Survey
</a>

 

Just enough difference to be a nuisance! But note that in both we have three copies of “Respond to this Survey” to change. One in the A tag, one in the IMG tag and one at the end of the A tag (and for 2010, inside a SPAN tag).

Now for some detective work:

So how do we find the one A tag out of all of the HTML on this page? I never depend on IDs with lots of strange characters (they tend to change from page to page) so that leaves out the normal best solution:  document.getElementById(“ctl00 ….. “). We could just loop through the A tags looking for one with a title of “Respond to this Survey”. And that will work fine, but as a best practice we may want this to work regardless of the language settings used to create the site.

So I see two other useful possibilities, find A tags with an ID that ends with “IONewItem” or find IMG tags that have ‘src="/_layouts/images/NewItem.gif"’. I’m going to use the first of these two.

 

So first let’s find the A tag: 

var atags = document.getElementsByTagName("A");
for (var i=0;i<atags.length;i++)
{
  if (atags[i].id.indexOf("IONewItem")>0)
  {
    // make text changes here...
  }
}

Now let’s change the text:

The first change is easy. As we already have found the “A” tag (atags[i]) all we need to is change the title property:

var newsurveytext = "Click here for the survey!";
atags[i].title = newsurveytext;

The second change is not too hard… The A tag contains two or three child nodes and the first one is the image. All we need to do to it is change the ALT attribute:

atags[i].childNodes[0].alt = newsurveytext;

We need to be careful with the next part as we want it to work in both 2007 and 2010. As 2007 has two nodes (IMG and the text) and 2010 has three nodes (the IMG, the “&#160;” text and the SPAN) we just need to check the count of nodes to make the correct edit for each version:

if (atags[i].childNodes.length == 2)
{
  // must be 2007  ("\u00A0" is to replace the &nbsp;)
  atags[i].childNodes[1].nodeValue = "\u00A0" + newsurveytext;
}
else
{
  // must be 2010 (and we hope the next version!)
  atags[i].childNodes[2].innerText = newsurveytext;
}

 

So here’s the final solution:

<script>

var atags = document.getElementsByTagName("A");
for (var i=0;i<atags.length;i++)
{
  if (atags[i].id.indexOf("IONewItem")>0)
  {
    var newsurveytext = "Click here for the survey!";
    atags[i].title = newsurveytext;
    atags[i].childNodes[0].alt = newsurveytext;
    if (atags[i].childNodes.length == 2)
    {
      // must be 2007  ("\u00A0" is to replace the &nbsp;)
      atags[i].childNodes[1].nodeValue = "\u00A0" + newsurveytext;
    }
    else
    {
      // must be 2010 (and we hope the next version!)
      atags[i].childNodes[2].innerText = newsurveytext;
    }
    break;  // no need to check the other A tags
  }
}

</script>

 

To add the JavaScript to SharePoint 2007

  1. Go to the survey page (overview.aspx)
  2. Click Site Actions and Edit Page
  3. Click Add a Web Part and select the Content Editor Web Part
  4. Move the Content Editor Web Part below the existing survey web part (important!)
  5. Edit the Content Editor Web Part and click the Source Editor button
  6. Copy and Paste the JavaScript above, changing the “newsurveytext” to your text
  7. Save and test

Or… edit the page (overview.aspx) in SharePoint Designer and add the JavaScript just be for the closing tag for the placeholder named “PlaceHolderMain”.

To add the JavaScript to SharePoint 2010

  1. Open Notepad, Copy and paste the JavaScript above, changing the “newsurveytext” to your text
  2. Save the file to a local drive
  3. Upload the file to a SharePoint library (while Shared Document will do, you may want a add a library just for these kinds of files)
  4. Go to the library where you just uploaded the file and copy the URL to the file (right-click the file and click Properties to find the URL)
  5. Go to the survey page (overview.aspx)
  6. Click Site Actions and Edit Page
  7. Click Add a Web Part and select the Content Editor Web Part
  8. Move the Content Editor Web Part below the existing survey web part (important!)
  9. Edit the Content Editor Web Part and paste the URL to the JavaScript file into the Content Link box
  10. Save and test

Or… edit the page (overview.aspx) in SharePoint Designer and add the JavaScript just be for the closing tag for the placeholder named “PlaceHolderMain”.

 

.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.