2

I am creating some site columns using javascript. And also I am creating content types. I am attaching these site columns to the content type with the <FiedRef> tag. But I want different default values to these site columns for different content types. Consider I am having site column as Capital. I am creating content types as US, India, UK etc. I have added Capital site column to US, India, UK content types. I have added these content types to one list called, Countries. Now when I select India content type the default value for Capital column should be "Delhi", when I select US the default value of Capital column should be "Washington DC" etc. I read MSDN article which is saying Default Value for site column is obsolete. But even it won't display the site column, I want to have in content type definition. How to achieve?

0

No you can't do that because this will defy the purpose of Site Columns which are intend to be global in nature.

Workaround is to set the default value after adding the content type to a list.

  • Seems this is the thing I am looking for. Could you please explain more on this? – Mihir Jul 7 '16 at 16:55
  • After you associate the content type to a list. You can go to list settings and select the field settings and change the default value to whatever you want. You can also automate this process by creating the list using JavaScript for example. – Amal Hashim Jul 7 '16 at 16:57
  • Yes I want to automate this in javascript – Mihir Jul 7 '16 at 17:05
0

Since you tagged the question with , I'll give you a Javascript answer.

Theoretically you could do this through Client Side Rendering. You would need to create a script for each content type, and attach it to the content type through the content type's JSLink property.

Then of course, in each script, you would set the field's value to the appropriate value for that content type.

  • One CSR script for the Field on an Edit/New Form, which (by ContenTypeid) sets the defaultvalue. ContentType for NewForm code: sharepoint.stackexchange.com/questions/126704/… – Danny '365CSI' Engelman Jul 7 '16 at 19:00
  • That is a good solution too -- attach the script to the field, and as it is rendering, check which content type it belongs to and populate default value based on that. I like it. – Dylan Cristy Jul 7 '16 at 19:02
  • Actually I did like this earlier, but my Manager is not accepting this solution. he wants as default value in the <FieldRef> only. – Mihir Jul 7 '16 at 20:21

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.