2

I have a list content type and other content types that derive from it. I need to add a lookup or choice column to the content type (or the list itself) just so that each child content type or list has separate set of options.

For example the parent content type is Assets. The content types deriving from it are Computers and Furniture. I need to add a column named "Asset_Type" that will list "Desktop, Laptop, Tablet" if the content type is Computer and it will list "Table, Chair, Desk" if the content type is Furniture.

I tried various scenarios with site columns but everytime ended up overwriting the parent column options and vice-versa. What should I be doing to make it work?

2

You should add two separate site columns, one for each derived content type.

You could name first site column "computer asset type" for use in "computer" content type with lookup or choice values "desktop,lptop,tablet". Similarly, you could name second site column "furniture asset type" for use in "furniture" content type with lookup or choice values "table,chair,desk"

EDIT:

If you choose to use solution with one generic column then you should inject the following JavaScript code to forms used for entering and editing list data:

var dropdown = $("select[title='Asset type']");

// If content type equals "Computer" then remove first 3 options
if (document.URL.indexOf("Computer") != -1 && document.URL.indexOf("Upload.aspx") != -1) {
    dropdown.find("option[value='1']").remove();
    dropdown.find("option[value='2']").remove();
    dropdown.find("option[value='3']").remove();
}

// If content type equals "Furniture" then remove last 3 options
if (document.URL.indexOf("Furniture") != -1 && document.URL.indexOf("Upload.aspx") != -1) {
    dropdown.find("option[value='4']").remove();
    dropdown.find("option[value='5']").remove();
    dropdown.find("option[value='6']").remove();
}
  • Thanks @Slaven. Yeah I could have done that, but I was hoping to create a generic column "Sub_Type" in the parent content type when showing in the AllItems View in which all the assets (computers, furnitures etc) are listed. I would prefer not to show two separate columns for the generic view. – Aamir Jan 1 '15 at 18:26
  • You could have 2 views, one for each content type. In each of the views you can then hide column which is not used. Solution with one generic column is also an option but it requires injecting a piece of javascript code which would hide certain values from dropdown list based on selected content type. – Slaven Semper Jan 1 '15 at 18:57
  • Yes I got that. I guess then there is no OOTB solution to have a single view that lists all the assets with their sub types shown in a single generic subtype column. Fair enough. Thanks for all the help! – Aamir Jan 1 '15 at 19:42
  • Another thing. When I added the [Content Type] column in the view by marking the checkbox, I was expecting to see the actual child content type (Computer, Furniture etc). Instead I only see "item" listed under the [Content Type] column. How can I get the actual child content type name? – Aamir Jan 1 '15 at 20:03
  • This leads to another question. How do I filter on Computers only content type when I am creating a view for computers only. As I mentioned earlier, the [Content Type] column returns only the generic "item" string and not the immediate "Computer" or "Furniture". – Aamir Jan 1 '15 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.