locked
Set default value of a column based on the value of a property in the site property bag?? RRS feed

  • Question

  • Background

    I have a site collection in which people are looking to manage projects, and the contracts that relate to the project, so the site hierarchy will be something like the following:

    Top Site
    - Project Site1
    -- Contract 1 for Project 1
    -- Contract 2 for Project 1
    -- ...other contract site as required
    - Project Site 2
    -- Contract 1 for Project 1
    -- Contract 2 for Project 1
    - Other Project Sites as required...etc

    There will be two separate site templates - a project site template, and a contract site template, but these will just ensure that the sites have the minimum required lists/libraries, and the project manager may add additional lists/libraries to these sites as required.

    In order to ensure that search will be effective, I would like to tag all list/library items in a project site with the project code
    Likewise, I woudl like to tag all list/library items in a contract site with the contract ID and the project code

    Proposed Approach

    The approach I am planning on taking with this is the following:

    For sites based on the project site template, use the site property bag to store the project code of the project
    For sites based on the contract site template, use the site property bag to store the project code of the project, and also the Contract ID

    All lists/libraries in sites based on the project site template will have a Project Code column added to them
    All lists/libraries in sites based on the contract site template will have Project Code and a Contract ID column added to them

    When an item is added/created in a list/library, I would like to default the project code and the contract ID columns (as required) so that the information is accurate, and the user doesn't have to bother with the filling in this metadata.

    Questions

    So I have a couple of questions in regard to this:

    1. Can anyone see any issues with the approach I have proposed, or is there a better way of achieving a similar result (ie good quality metadata for search)?

    2. Assuming that I take the approach outlined above, what are the different approaches for setting the default value of the columns when an item is added, and which of the possible approaches would be recommended keeping in mind that additional document libraries may be added after the site is created??

    Thanks in advance for any assistance!!

    Wednesday, July 11, 2012 12:48 AM

Answers

  • Just in case it is useful for someone down the track, I managed to achieve what I was looking to do by creating a custom field type, following the walkthrough here: http://msdn.microsoft.com/en-us/library/bb861799.aspx

    this allows me to create columns based on the custom field type, which will check if a property bag value exists at the site level, and if it does, this will be used as the default value for the column.

    Seems to work very well - giving users the flexibility to add this column to their lists, and have it automatically populate. This should give us more consistent metadata, without having to deploy custom content types every time someone wants to use the column.

    Next step is to create a layout page which will allow users to manage the site property bag values.

    • Marked as answer by arduk1 Wednesday, July 25, 2012 10:42 PM
    Wednesday, July 25, 2012 10:42 PM

All replies

  • When creating a column, there is a textbox there where you can enter the default value of that column.

    ----------------------- Sharepoint Newbie

    Wednesday, July 11, 2012 1:44 AM
  • Hi Fix Me, thanks for getting back to me.

    I am aware that there is a text box for specifying the default value, however if I use this, it will mean that for every time I create a site, I am required to manually set the default values for every list/library in the site, which is not going to be practical (there could be a large number of these sites)

    I am looking to create a method so that I only have to set the value for these values once (eg in the site property bag), and it will apply to all lists and libraries within that site.

    Wednesday, July 11, 2012 1:59 AM
    1. Is the Project Code and Contract ID going to be editable by the end user? 
    2. Or are you planning to just have these metadata columns just pre-populated and the end user never has to edit it?

    The second option would be simpler since

    • You could make these columns read-only which will prevent them from showing up in add/edit forms
    • Add these columns to the default view so the user sees the values populated after the item is created.
    • Create an event receiver and bind it to your lists or better if you have a content type hierarchy then bind the event receiver to the content type so it only has to be done at the site collection level once.

    With the first option you would need a separate feature that when activated would set the default column value.  In which case I assume that these are list level columns and not site level columns.

    Anand

    • Proposed as answer by Anand . Ramanan Wednesday, July 11, 2012 4:15 AM
    • Unproposed as answer by arduk1 Wednesday, July 11, 2012 4:33 AM
    Wednesday, July 11, 2012 2:39 AM
  • Hi, thanks for getting back to me

    In answer to your questions, I would probably look at having the fields read only, so they don't have to edit it.

    I like the idea of an event receiver bound to a content type, but is it possible to bind an event receiver to a field (ie a site column) rather than a content type?

    I am thinking that if I can bind it to a field, it will make it more useful, as it would be able to be used in the content type hierarchy that I am planning, but also would allow the field to be used in other ad-hoc lists - eg if a user creates a custom list within a site, they could just add the site column at the list level, and it would still automatically populate with the correct value.

    Would a custom field be able to achieve this? or is there a better way of doing it?

    Thanks again for your assistance!

    Wednesday, July 11, 2012 3:33 AM
  • Cannot bind event receivers to a column.  It would be good if you can define the necessary content types and bind them to the content type.  If that is not possible then bind it to the individual list.

    Anand

    Wednesday, July 11, 2012 4:14 AM
  • It is going to be quite limiting if I have to bind an event receiver to every content type or every list - it will mean that the column can only be used in content types that are custom developed, rather than in custom lists which are created by users.

    I am thinking that the best way to do this may be through a custom field type (see http://msdn.microsoft.com/en-us/library/gg132914.aspx), as this should allow me to set the default value, but I will have to try this before I can confirm.

    Is there anyone who has created a custom field type, and can confirm that this will allow me to achieve what I am looking to do?

    Thanks in advance!

    Wednesday, July 11, 2012 4:38 AM
  • Just in case it is useful for someone down the track, I managed to achieve what I was looking to do by creating a custom field type, following the walkthrough here: http://msdn.microsoft.com/en-us/library/bb861799.aspx

    this allows me to create columns based on the custom field type, which will check if a property bag value exists at the site level, and if it does, this will be used as the default value for the column.

    Seems to work very well - giving users the flexibility to add this column to their lists, and have it automatically populate. This should give us more consistent metadata, without having to deploy custom content types every time someone wants to use the column.

    Next step is to create a layout page which will allow users to manage the site property bag values.

    • Marked as answer by arduk1 Wednesday, July 25, 2012 10:42 PM
    Wednesday, July 25, 2012 10:42 PM
  • Hi arduk1,

      Good solutions.  To address your site property bag values management.  There exists a solution for this available from codeplex at http://portalsolutions.codeplex.com/wikipage?title=PS%20Config%20Tool&referringTitle=Documentation

    Anand

    Friday, July 27, 2012 7:27 PM