Friday, March 09, 2007

Custom Link field in a SharePoint Document Library

I have a document library with various content types. Depending on the content type I wish to display different graphics, i.e. not just displaying the name of the content type but a graphics file instead., i.e. similar to the "URL (URL with edit menu)" field outlined below:


Depending on the version of the file I also wish to display different fields. I would like the published version of the file to be accessed from the same link always - and if a minor version exists this version should be accessed from another link in the list.

I have tried to create a feature with a custom field that contains exactly this stuff - no luck. The new custom field simply doesn't show up in my view.

I came across this blog but I couldn't get it working :-( Couldn't add an IF statement in a computed field. I got the error "The formula contains a syntax error or is not supported. " when I tried to add the IF statement. As a next step I studied the difference between Computed and Calculated fields as outlined in this blog. When I add the field as a Calculated field the above blog works - voila. However, changing fldtypes.xml is not recommended - would like to get it working using standard features. The other issue is that I would need to add this calculated field to all my document types in order to enable field selection on a view.

The issue currently is the fact that computed fields cannot easily be added to list or views - at least they don't show up if added as features. Calculated fields does.

Remember the difference between the two field types: Computed fields are not stored in the database but calculated fields are.

Further - you need to note the difference between columns, fields and properties - as described in this blog.

Still not fully understanding what is going on it seems that calculated fields are not really columns - so they cannot be viewed in the Site Columns collection (despite the fact they are added with other fields as part of the same feature). Neither - unfortunately - they cannot be added to a view.

If I look into the SPWeb object
.AvailableSiteColumns('')
my column is returned. But how can I add it to the view?

Apparently other people have had this issue too - here and here.
In SharePoint 2003 I simply modified onet.xml to accomodate this new field, as outlined here.

5 comments:

Anonymous said...

Brilliant web site, I hadn't noticed mqsharepoint.blogspot.com before during my searches!
Carry on the superb work!

Anonymous said...

Hello there,

Thanks for sharing the link - but unfortunately it seems to be down? Does anybody here at mqsharepoint.blogspot.com have a mirror or another source?


Thanks,
Peter

Morten Marquard said...

Which link do you refer to?

Anonymous said...

Hi there,

Thanks for sharing this link - but unfortunately it seems to be down? Does anybody here at mqsharepoint.blogspot.com have a mirror or another source?


Cheers,
Alex

Anonymous said...

Hi - I am certainly glad to find this. great job!