Wednesday 17 June 2009

Removing Lookup Link from SharePoint List.

Found a good post on SharePoint Kings on how to get around this:
http://www.sharepointkings.com/2008/10/remove-link-on-lookup-field.html

if the site is unavailable here is the code needed:

<script language="javascript" type="text/javascript">

_spBodyOnLoadFunctionNames.push("RemoveLookupLinks");
function RemoveLookupLinks()
{
var oP = document.getElementsByTagName('a');//the collection of <a> tags
var flag = false
for(var i=0;i<oP.length;i++)
{
if(oP[i].attributes["href"].value.indexOf("RootFolder=*")!= -1)
{
var linkvalue = oP[i].innerHTML;//value of the lookup field
oP[i].parentNode.innerHTML = linkvalue;//replacing value of the lookup to whole the Anchor tag
flag = true;
break;
}
}
if(flag)
RemoveLookupLinks();
}
</script>

It does mean either hacking the default master or creating your own, which isnt too hard with SharePoint Designer.

Problem for me was, if you had multiple choices on the lookup fields only the first choice was saved.

so I put in a small fix
Replace:

var linkvalue = oP[i].innerHTML;//value of the lookup field

With:

var linkvalue = oP[i].parentNode.innerHTML;
var re = new RegExp("<[aA][^>]+>","gi");
linkvalue = linkvalue.replace(re,"");
var re2 = new RegExp("</[aA][^>]*>","gi");
linkvalue = linkvalue.replace(re2,"");


Now, my regex isnt great, but it works and that is the main thing.


Read the post if you want to see more detail, but I just added a small change to the script which allows multiple links to be replaced.

Friday 12 June 2009

Using [Today] in a Calcuated field

Without going into some development of a computed field, dont bother thinking about doing this, it is a useless concept (unless you want a static generation).

Using Today in a calculated field will only work out the calculation at time of save, and I also read a post that suggested using the Modified date to get the same effect.

Without going too much outside the box, there is not a lot I would encourage doing.
Using Designer some suggest manipulate the listview in an xslt template and use JavaScript to manipulate the date, but then you have to do this to all the views you have created as well as the detail view (dispform) and stop people creating more or personal views, which will be a big pain. From my own experience and of the flakiness of SharePoint Designer I managed to kill an entire list when trying to javascript the views in this way.

So in summary try to avoid using calculated fields if you want the value to be dynamic.

And dont worry about trying to use Today if you do want a value, use Modify.

I am just one man with a very narrow view on what can be done with SharePoint, but to make my job easier if SharePoint does not do it out the box then I dont really want to waste my time with getting into support and development for all the sites we run.

So long as the end user knows the constraints of the system out the box they tend to understand.