1

I have a program that is creating some lists and adding the necessary fields to the lists in SPO.

I have marked some of these fields as Required, but in list settings they do not show up as Required. However when I try to create a record using the OOB form, it says these fields are mandatory.

How can I fix this?

Code for adding the field: Field description = list.Fields.AddFieldAsXml("<Field DisplayName='Description' Type='Note' NumLines='6' Required='True'>", true, AddFieldOptions.DefaultValue);)

Also, is there a way to modify the OOB forms for these dynamic lists?

  • I would like the default New form to not show some of the fields added.
  • I also want to have a new form where I can edit only a single field

EDIT: I now understand that if I set ShowInNewForm = 'FALSE' the field will not show up in the new form

1
  • Please share your code to understand what exactly is the issue with the code Commented Jun 2, 2023 at 3:35

2 Answers 2

1

I was able to reproduce this, I think it's one of those old quirks in SharePoint where 'True' isn't always true, unfortunately.

If you update your field xml with Required='TRUE' you might find you get what you want.

1

Regarding the Required property not showing up correctly in the list settings, this issue can occur when adding fields programmatically. One possible solution is to update the field after it has been added to the list. You can use the Field.Required property to set the Required attribute separately.

Here's an updated version of your code that includes updating the Required property after adding the field:

Field description = list.Fields.AddFieldAsXml("<Field DisplayName='Description' Type='Note' NumLines='6' Required='True'>", true, AddFieldOptions.DefaultValue);
description.Required = true;
description.Update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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