none
Using [Content Type] in calculated column formula RRS feed

  • Question

  • I'm trying to use the [Content Type] value in a calculated column formula. For example :

    =IF([Content Type] = "Task", "This is a task", "Not a task")

    Using this generates an error when saving the column definition. 

    Is it possible to use the Content Type value in a calculated column? If so, how do I reference this value.

    Thanks,

    Joe

     

     


    Joseph Amen
    Thursday, December 2, 2010 9:17 PM

Answers

  • Computed fields are mainly used internally by SharePoint.

    Here are a few examples/information about computed fields:

    - http://office.microsoft.com/en-us/sharepoint-designer-help/introduction-to-building-sharepoint-applications-HA010239046.aspx

    - http://www.moss2007.be/blogs/vandest/archive/2009/03/31/advanced-computed-field.aspx 

    There are not many information about this field. It's basically CAML that produces an output. In SharePoint 2010 DisplayPattern (in the field definition no longer works, you need XSL) so it's rather tricky (also since there is no read tutorial on the subject). To understant how a computed field works, the best way is to look inside the standard list definitions schemas to see what has been done inside SharePoint.

    Event receiver is in my opinion the simplest way .. or a workflow if you prefer doing it with SharePoint designer to avoir C# dev.


    Florin DUCA
    MCSE 2003 +Sec,MCTS conf/dev WSS3/MOSS, MCITP/MCPD SP 2010, MCPD ASP.Net 3.5, MCTS ISA 2006
    Logica Business Consulting, France
    • Marked as answer by Lily Wu Friday, December 10, 2010 8:46 AM
    Friday, December 3, 2010 3:57 PM
  • One workaround I have used for this issue is to add a custom field to a content type, and then check its value.  For example, I might add a yes/no field called IsTask to the Task content type, and default it to Yes.  The the formula would look like this:

    =IF([IsTask], "This is a task", "Not a task")

    There are some additional complications in using a yes/no field this way, since the UI won't let you mark them as hidden.  (Why not?)  But you can hide them behind the scenes by setting the ShowInDisplayForm, ShowInEditForm, and ShowInNewForm values.  Or if you don't like going behind the scenes, simply use a text field instead.

    • Marked as answer by Lily Wu Friday, December 10, 2010 8:46 AM
    Friday, December 3, 2010 4:02 PM

All replies

  • Its not offering the content type column for calculation purposes, so you'll have to go with the XSLTListView and SharePoint Designer
    Thursday, December 2, 2010 9:37 PM
  • In calculated fields you cannot use lookup fields (and I suppose content type is a sort of special lookup field). A possible solution would be either using computed fields (cannot be created using the web interface) or use an event receiver (or workflow if you prefer it).
    Florin DUCA
    MCSE 2003 +Sec,MCTS conf/dev WSS3/MOSS, MCITP/MCPD SP 2010, MCPD ASP.Net 3.5, MCTS ISA 2006
    Logica Business Consulting, France
    Thursday, December 2, 2010 9:55 PM
  • Thanks for responding. I'm not familar with computed fields, can you send a link that outlines this technique? Thanks, Joe
    Joseph Amen
    Friday, December 3, 2010 1:59 PM
  • Computed fields are mainly used internally by SharePoint.

    Here are a few examples/information about computed fields:

    - http://office.microsoft.com/en-us/sharepoint-designer-help/introduction-to-building-sharepoint-applications-HA010239046.aspx

    - http://www.moss2007.be/blogs/vandest/archive/2009/03/31/advanced-computed-field.aspx 

    There are not many information about this field. It's basically CAML that produces an output. In SharePoint 2010 DisplayPattern (in the field definition no longer works, you need XSL) so it's rather tricky (also since there is no read tutorial on the subject). To understant how a computed field works, the best way is to look inside the standard list definitions schemas to see what has been done inside SharePoint.

    Event receiver is in my opinion the simplest way .. or a workflow if you prefer doing it with SharePoint designer to avoir C# dev.


    Florin DUCA
    MCSE 2003 +Sec,MCTS conf/dev WSS3/MOSS, MCITP/MCPD SP 2010, MCPD ASP.Net 3.5, MCTS ISA 2006
    Logica Business Consulting, France
    • Marked as answer by Lily Wu Friday, December 10, 2010 8:46 AM
    Friday, December 3, 2010 3:57 PM
  • One workaround I have used for this issue is to add a custom field to a content type, and then check its value.  For example, I might add a yes/no field called IsTask to the Task content type, and default it to Yes.  The the formula would look like this:

    =IF([IsTask], "This is a task", "Not a task")

    There are some additional complications in using a yes/no field this way, since the UI won't let you mark them as hidden.  (Why not?)  But you can hide them behind the scenes by setting the ShowInDisplayForm, ShowInEditForm, and ShowInNewForm values.  Or if you don't like going behind the scenes, simply use a text field instead.

    • Marked as answer by Lily Wu Friday, December 10, 2010 8:46 AM
    Friday, December 3, 2010 4:02 PM