2

Trying to add Multiline Enhanced Rich Text field to a SharePointOnline Document Library using JSOM. The field appears properly in classic mode but gives 404 NOT FOUND error when clicking on the Pen (edit button) in modern experience. Sample Code:

var fieldSchema = '<Field Type="Note" DisplayName="Feedback" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" NumLines="6" UnlimitedLengthInDocumentLibrary="TRUE" RichText="TRUE" RichTextMode="FullHtml" IsolateStyles="TRUE" Sortable="FALSE" ID="{450158A2-AD0C-46A5-9108-BB1D3FA3649B}" StaticName="Feedback" Name="Feedback" ColName="ntext2" RowOrdinal="0" />'
var clientContext = new SP.ClientContext();
var targetList = clientContext.get_web().get_lists().getByTitle('Documents');
var fieldCollection = targetList.get_fields();
fieldCollection.addFieldAsXml(fieldSchema, true, SP.AddFieldOptions.addToDefaultContentType);
clientContext.load(fieldCollection);
clientContext.executeQueryAsync(function () {console.log('success');}, function() {console.log('failure');});
  • Looks like a bug ? Would suggest that you raise the issue here . Have a similar requirement wherein i use the /_api/web/lists/getByTitle('Test')/fields REST endpoint with SchemaXml property and works fine. Also, just FYI, MS is kinda deprecating JSOM, so you might start wanting to move your code to REST. Ref - create field via REST – Gautam Sheth Apr 26 '18 at 6:38
  • Thanks @GautamSheth, reported the issue: github.com/SharePoint/sp-dev-docs/issues/1759 – Nadeem Yousuf Apr 26 '18 at 10:39

Your Answer

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

Browse other questions tagged or ask your own question.