Many of you out there in SharePoint land will from time to time have the need to edit a list definitions schema.xml file to create your custom list. You may also have need to edit the List View in that schema file to create a different kind of view, one not possible to create by the SharePoint UI.
I have had need to do this recently. I needed a List View that highlighted expired items or tickets in my list. It needed to make them go red.
Now you might think that’s easy enough create a calculated field that does date maths on the date you have in the list item and the current date that gives basically 1 or 0 for expired or not. Well you’d be wrong. You see you can’t use [Today] or anything like it in a calculated field the list wants fixed not dynamic values in it and will not allow Dynamic values, think about it, it would seriously effect performance.
Starting with a function definition that takes parameters and then spits out one TD tag or another based on the date difference, I placed this in the <ViewHeader> section of my custom view.
The next bit was the bit I was struggling with as because I was new to this I was calling my function in the <ViewBody> section where I replaced the normal output of a TD tag with this.
Well this kind works, but the problem is that the <FIELD> tag output the HTML required to make it look good in a list. Now in my case the date had <NOBR> tags around it, and the SLA is a lookup so has a bit <A> link around it.
Now if a Service pack comes along and changes the render for the <FIELD> tags, my code is then scuppered, the regex I employed to strip out the data could become a nonsense. But I could not find any attribute of the Field Tag to spit out the Data value not the render text.
The reason behind this is simple, its related to RTFM! The is an element of the List View schema called <Column> it is responsible for outputting values unformatted. It also has additional attributes the <FIELD> does not to allow formatting of data like a date format.
My code now reads like this
Notice the user of the Format=”ISO8601″ attribute of the date column.
Now my list view can display items that have expired in an alternate colour.
One downside is that the Column for the Lookup field shows the ID only, which in a Listview might be restrictive and the <Column2> tag does not display the text as it would do for a URL field. Luckily for me my lookup list is unchangeable security blocks modifications.
So it’s really worth opening the WSS3 SDK and navigate to
General Reference->Reference->Collaborative Application Markup Language Core Schemas
and take a look at all the schemas you may have to edit before you try and crowbar something in that already exits.