1

I have to set the default value to choice column which is custom column as-

 <Field ID="{76880880-e435-4367-84e9-04840e60aa52}" Name="testChoice" DisplayName="Test Choice" StaticName="Test Choice" Type="Choice" Required="FALSE" Group="SMC"><Default>Yes</Default><CHOICES><CHOICE>Yes</CHOICE> <CHOICE>No</CHOICE></CHOICES></Field>

Is it possible?

  • Any error you are getting. It seems you field definition is valid. – Atish Dipongkor - MVP Aug 30 '16 at 9:42
  • No, I don't have any error. But I need this should be selected to "Yes" while adding the new item. – Ram Aug 30 '16 at 9:46
  • Yes should be selected according to your code. Did you try? – Atish Dipongkor - MVP Aug 30 '16 at 9:48
  • Yes, I have tried this, but not yet getting me as I needed. – Ram Aug 30 '16 at 9:50
1

Try to use Fields.AddFieldAsXml as the following

  string CustomField = string.Concat("<Field Type='Choice' DisplayName='",
        columnName, "' Name='", columnName, "' ",
        "Format='Dropdown' Required='TRUE' Indexed='TRUE'><CHOICES>",
        "<CHOICE>Qassas</CHOICE><CHOICE>Item0</CHOICE>",
        "<CHOICE>Item2</CHOICE><CHOICE>Item1</CHOICE>",
        "<CHOICE>Item3</CHOICE><CHOICE>Item4</CHOICE>",
        "</CHOICES><Default>Qassas</Default>",
        "<Description>any thing.",
        "</Description></Field>");

        list.Fields.AddFieldAsXml(CustomField , true,
            SPAddFieldOptions.AddFieldToDefaultView);
        list.Update();
  • What changes need to do in my tag- <Field ID="{76880880-e435-4367-84e9-04840e60aa52}" Name="testChoice" DisplayName="Test Choice" StaticName="Test Choice" Type="Choice" Required="FALSE" Group="SMC"><Default>Yes</Default><CHOICES><CHOICE>Yes</CHOICE> <CHOICE>No</CHOICE></CHOICES></Field> – Ram Aug 30 '16 at 9:40
  • I am sorry I answered this based on your quest before update , regarding your update your field tag structure looks good, so what's the issue – Mohamed El-Qassas MVP Aug 30 '16 at 9:43
  • If not set as default , Should you try to deactivate the feature and restart IIS then activate it again – Mohamed El-Qassas MVP Aug 30 '16 at 9:48
  • Yes, I have deactivated and again activated that feature. Also I have removed content type from the list and again assigned still it's not working. – Ram Aug 30 '16 at 9:48
  • try to set <Default>Yes</Default> after the choices – Mohamed El-Qassas MVP Aug 30 '16 at 9:52

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.