Using Javascript to Manipulate a List Form Field Title

October 12th, 2007 by Dor

Lets say you want to change the text of a field title in a new item form, or in an edit-item form. You might want to do one of the following:

  • Change the field title text
  • Add a remark to the title
  • Add a link
  • Make the title a link
  • Put some javascript

The trick in doing this is also not breaking the Form Web Part, so new fields will appear in the form.

The solution is… Javascript at runtime! It’s inspired by this post for changing the default value of a field, only this time we’re talking about the title text and not the field value.

So how to do it? Easily. Open the NewForm page with SharePoint Designer and view the HTML code. Look for the main content placeholder:

<asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”>

Paste this code inside it, before the table:

<!– Begin Field Link Code –>
<script type=”text/javascript”>
// Add the function so it will be called on Body_OnLoad.

function AddFieldLinks()
  // Call the search function with an anonymous function that will 
// be executed upon finding the relevant field.
AddFieldLink(“Status”, // This anonymous function adds a link to the field’s title. function (currentText) { return currentText + “<br/>” +
GenerateLink(“policy.html”, “<u>See Status Policy Document</u>”); } ); } function GenerateLink(url, text) { return “<a target=\”_blank\” href=\”" + url + “\”>” + text + “</a>”; } function AddFieldLink(fieldName, fn) { // Get all field titles var tags = document.getElementsByTagName(“H3″); // Go through all field titles and search for the requested field. for(var i=0; i < tags.length; i++) { if((tags[i].children.length == 1) &&
(tags[i].className == “ms-standardheader”) && ((tags[i].children[0].innerText == fieldName) ||
(tags[i].children[0].innerText == fieldName + ” *”))) { // Found the field we need to update. Set its tags[i].children[0].innerHTML = fn(tags[i].children[0].innerHTML); break; } } } </script> <!– End Field Link Code –>

Now just edit the body of the AddFieldLinks function to change the title of the relevant fields.

It’s parameters are:

  • The title of the field
  • A function that returns a string for the title.
    Notice that I used an anonymous function so you can set a different behavior for each field title - for example, one will be a link, the other would be appended some text, etc…

Now just save the file, approve the unghosting, and that’s it! Smile

Here’s the result - click to enlarge:
click me!


Posted in English Posts, WSSv3 | No Comments » Javascript to Manipulate a List Form Field Title digg:Using Javascript to Manipulate a List Form Field Title reddit:Using Javascript to Manipulate a List Form Field Title

SPD ‘Send Email’ Workflow Activity HTML Message Body

August 28th, 2007 by Dor

Would you like to send email messages with a rich text body from your custom SharePoint Designer workflow? Well, it’s easier than you think…

Appearatnly the out of the box activity sends the message body as HTML, but the editor is not rich, thus misleading us to think we can only insert simple text. However, the solution is to simply paste HTML code into the body. And that’s it! Open-mouthed

This way you can create messages with cool content, and align the body as RTL (Right To Left) for relevant languages such as Hebrew.

Here’s a screenshot from SharePoint Designer in Hebrew, in which I created an RTL message:


Tip: Check the Workflow XOML file that SPD creates before running it for the first time. (Because on the first run it will compile and workflow will become unchangable.) See the HTML string you created and run it through some HTML Decoder, to convert special characters to understandable text. Then you can make sure the HTML is OK.

Posted in English Posts, Office 2007, WSSv3 | 2 Comments » 'Send Email' Workflow Activity HTML Message Body digg:SPD 'Send Email' Workflow Activity HTML Message Body reddit:SPD 'Send Email' Workflow Activity HTML Message Body

Stock Quote Web Part(s)

August 16th, 2007 by Dor

Yesterday I was asked to put a web part on an internal MS site, which displays Microsoft’s stock current value and a graph to show its changes.

This appeared to be easy - Yahoo offers these kind of web widgets that can be embedded in a site.

However, the Yahoo widget has a big logo and commercials, and this isn’t suitable for an internal MS site. So I needed to get the data elsewhere.

After some research I found a way to do this, using MS only tools:


So I separated the functionality to two Web Parts:

  • Data View Web Part (created using SharePoint Designer) - to consume the Web Service
  • Content Editor Web Part - to run some javascript to get the chart image

If you’re interested in how I created the Web Parts, keep on reading. Otherwise, skip to the end of the post to download them.

1. The Stock Value Web Part

That’s easy - open up SharePoint Designer, open some SharePoint page you can edit on a test site, and connect to a data source - the MoneyCentral Web Service. You’ll get the data, which you can add to your page using the Data View Web Part.

However, there’s a problem - the Web Service output is a string that contains a lot of XML data as a String and not as a complex XML tag. SharePoint Designer doesn’t know the schema of that XML and can’t isolate just the current value of the stock from it. So I used a couple of functions to isolate the relevant text. (substring-before, substring-after.)

Then just save the page, view it in your browser, export it using the Web Part menu, and import it to wherever you want to place it. (By working on a test site and importing the Web Part, the page desination page will not be unghosted.)

2. The Stock Chart Web Part

This is a bit more tricky: you can take images straight from the MSN website, because the image source is a DLL that generates them on demand. You just need to send the right parameters.

Please notice that by using this trick, we’re actually “stealing” bandwidth and CPU from MSN’s servers. So the minimum I could do is put some nice link to MSN to give them credit..

I created a Javascript function that generates the URL:

formatChartImageSrc(symbol, fromDate, toDate, imgWidth, imgHeight)


  • symbol: a string containing the stock symbol name, like “MSFT”.
  • fromDate: a Date object containing the date from which to display the timeline.
  • toDate: the date in which the timeline will end (usually today)
  • imgWidth, imgHeight: Dimensions of generated image.

Here is a sample use of the function that outputs the URL for a 1-year view of the MSFT stock, until today. Then I get an IMG element with the ID “chart” and set it’s source to the generated URL.

var stockName = “MSFT”;
var toDate = new Date();
var day = 1000*60*60*24
var fromDate = new Date(toDate - day*365);

var srcUrl = formatChartImageSrc(stockName, fromDate, toDate, 300, 300);
var chartObj = document.getElementById(“chart”);
chartObj.src = srcUrl;

I place this code and the <img> tag itself in the Content Editor Web Part, and that’s it. The image will be up to date.

Download & Installation

Here are the links to the files:

Changing the stock symbol
After you save the Web Parts locally, open them in a text editor. Search and replace the word MSFT with the stock symbol you want to display. Do this before uploading the Web Parts to your website.

Importing the files to the site
To install, go to a SharePoint Site, click Site Settings and then Edit This Page. Add a Web Part to a zone, and then click the bottom link in the Add Web Part Dialog to get to the advanced mode. Now you’ll see the gallery on the side of the page. On the top of the gallery, you will see the word Browse. Click it and choose Import instead. Then pick one of the .webpart files and upload them. Drag and drop, repeat for the second file, and that’s it!

Posted in English Posts, MOSS, WSSv3 | 13 Comments » Quote Web Part(s) digg:Stock Quote Web Part(s) reddit:Stock Quote Web Part(s)

Windows Live Writer works again on this blog!

July 20th, 2007 by Dor

1. The Problem

I was unable to write using this cool application for a while now. The reason was this annoying error:

Invalid Server Response - The response to the blogger.getUsersBlogs method received from the weblog server was invalid.

So I did some research and found this post about changing the .htaccess file. Unfortunently it didn’t solve the problem.

Then I installed Fiddler 2, the wonderful HTTP proxy application. I started Windows Live Writer again and let it reconnect to my blog. I analyzed the response from XMLRPC.PHP after receiving the error again, and found this response from the server:

XML-RPC server accepts POST requests only.

I searched for this error and got to this post about the problem, which was close but didn’t solve it either. However, a link from the post to the support page on the PHP bug tracker showed me a different command to put in the XMLRPC.PHP file.

And it worked! Thanks Will! Open-mouthed

So now I’m writing this post using Windows Live Writer… finally!

P.S. Lovely link for troubleshooting WordPress and Windows Live Writer.


2. The New Stuff

So now I can do all sorts of nice things. First, I can embed videos - which I couldn’t using the WordPress default rich text editor. Also, I installed some add-ins for WLW:

You can see I can insert smilies such as these:

  • MSN  Open-mouthed
  • Yahoo Happy
  • CustomBanana(My favorite!)

And also I’m able to insert C# code and make it look cool:

MyObject obj = new MyObject(“foo”, 123);
int result = obj.DoStuff();
return result;

 In summary - maybe now I’ll start writing more Open-mouthed


Posted in English Posts | 2 Comments » Live Writer works again on this blog! digg:Windows Live Writer works again on this blog! reddit:Windows Live Writer works again on this blog!

Updating a list item without changing the Modified field

July 14th, 2007 by Dor

In WSS 3.0, it is now possible to update a list item (SPListItem) without changing the contents of the Modified or Editor fields.
This wonderful method is called SPListItem.SystemUpdate (has two overloads).

This solves the annoying problem where people would see some system user account that is responsible for the last update, and the time was also some strange time in which the system account did its actions.

So here’s the code sample:

SPSite site = new SPSite(“http://server/sites/someSite”);
SPWeb web = site.OpenWeb();
SPList list = web.Lists[“ListNameHere”];

// Create new item
SPListItem item = list.Items.Add();
item[“Title”] = “New Item Title”;
item[“Modified”] = new DateTime(2000, 1, 1);
item[“Created”] = new DateTime(2000, 1, 1);
item[“Author”] = web.Users.GetByEmail(“”);

// Update an item
// (Using some item ID from a pre-populated list)
SPListItem itemu = list.Items.GetItemById(2);
itemu[“Title”] = “An updated item title”;
itemu[“Author”] = web.Users.GetByEmail(“”);

Posted in English Posts, WSSv3 | No Comments » a list item without changing the Modified field digg:Updating a list item without changing the Modified field reddit:Updating a list item without changing the Modified field

New Outlook 2007 Preview Handlers!

April 16th, 2007 by Dor

My good friend Gil Azar has developed a very cool set of preview handlers for Outlook 2007.
Available file types for preview are: PDF, HTM, HTML, XML, ZIP, WMV, WMA, AVI, MP3, MIDI, and more.
You can find more information about the implementation and even the source code on his page. I’m already testing it on my machine and so far it works great. Go download it! :)

Posted in English Posts, Office 2007 | 2 Comments » Outlook 2007 Preview Handlers! digg:New Outlook 2007 Preview Handlers! reddit:New Outlook 2007 Preview Handlers!

An interesting revelation about publishing…

December 29th, 2006 by Dor

Sites that have the publishing feature active - can’t be saved as templates. This option simply dissappears from the site administration page when the feature is turned on.

You can get to the “Save As Template” web page by appending the page’s address (”/_layouts…”) to the site’s URL, however this action is unsupported and sites restored from the saved template might be broken.

If you’d like to migrate a site that uses the publishing feature, use STSADM or SharePoint Designer’s import/export abilities. And if you don’t need publishing - don’t turn it on.

Hope this will be resolved in a hotfix….

Posted in English Posts, MOSS | 1 Comment » interesting revelation about publishing... digg:An interesting revelation about publishing... reddit:An interesting revelation about publishing...

Windows SharePoint Services 3.0 Tools: Visual Studio 2005 extensions

November 7th, 2006 by Dor

(Via Meron Fridman’s Blog)

This Community Technology Preview (CTP) of the Visual Studio 2005 Extensions for Windows SharePoint Services contains the following tools to aid developers in building SharePoint applications:

Visual Studio 2005 Project Templates

  • Web Part
  • Team Site Definition
  • Blank Site Definition
  • List Definition

Visual Studio 2005 Item Templates (items that can be added into an existing project)

  • Web Part
  • Custom Field
  • List Definition (with optional Event Receiver)
  • Content Type (with optional Event Receiver)
  • Module

SharePoint Solution Generator

  • This stand-alone program generates a Site Definition project from an existing SharePoint site. The program enables developers to use the browser and Microsoft Office SharePoint Designer to customize the content of their sites before creating code by using Visual Studio.


Posted in English Posts, WSSv3 | No Comments » SharePoint Services 3.0 Tools: Visual Studio 2005 extensions digg:Windows SharePoint Services 3.0 Tools: Visual Studio 2005 extensions reddit:Windows SharePoint Services 3.0 Tools: Visual Studio 2005 extensions

Changing AND/OR Behavior in FREETEXT Searches

November 7th, 2006 by Dor

The default functionality of search in MOSS 2007 has changed:
From now on, all keywords in FREETEXT searches are linked with an “AND” operator between them. You will only receive results that contain all the words from the query. (The current product documentation is not up to date about this issue.)

This means that:

  • Searching for windows server will probably return results
  • Searching for windows server nonexistantword will return no results (unless you actually have a document with all of these words :)).

However, it is possible to perform an “OR” search programmatically, so that any item containing one or more of the keywords will be displayed. (Of course that items with more keywords will receive higher ranks accordingly.)

  • When using the Object Model: Set the KeywordInclusion property to All Keywords:
    query.KeywordInclusion = KeywordInclusion.AnyKeyword;
  • When using the Web Service: Insert the ImplicitAndBehavior element under the Query element and set its value to false:


Hope this information was useful to you,

Posted in English Posts, MOSS | 1 Comment » AND/OR Behavior in FREETEXT Searches digg:Changing AND/OR Behavior in FREETEXT Searches reddit:Changing AND/OR Behavior in FREETEXT Searches