mercoledì, luglio 25, 2007

SharePoint Customization: Lookup Columns and Calculated Values

Some neat information at this blog (quoting another blog, which I couldn’t gain access to).

 

Great tip from Dustin Miller

I mention in just about every Bootcamp that the biggest problem with calculated fields is that you can't use them in lookups. Well, the solution, as I mention in class, is to perform your calculations on the client-side. What I don't mention in class (it's a “SuperGeek Moment”, so it's meant to get the gears turning) is the actual code. Thus I have decided that I'm going to try and write a weekly “SuperGeek Tip”. This week's tip: Calculating “Full Name” using client-side script, so SharePoint is blissfully unaware that Full Name is anything but a plain text field.

At the bottom of the NewForm.aspx and EditForm.aspx for any default Contacts list, just above the closing element, add this code (inside a script block of course)

var lastName = document.getElementById("urn:schemas-microsoft-com:office:office#Title")
var firstName = document.getElementById("urn:schemas-microsoft-com:office:office#FirstName");
var fullName = document.getElementById("urn:schemas-microsoft-com:office:office#FullName");
lastName.onchange = fixFullName;
firstName.onchange = fixFullName;

function fixFullName() {
fullName.value = firstName.value + " " + lastName.value;
}

You can do this in FrontPage 2003, or you could modify the list definition files yourself (the so-called “Ghosted” template -- be aware, Microsoft doesn't support you touching those files if you've already deployed sites based on that site definition).

Once you've done this, adding contacts / editing contacts will both cause Full Name to calculate whenever the values of First Name or Last Name change.