0

When using JSOM to add a new site column to a 2013 SharePoint web, I get the following error

Column 'ProgramName' does not exist. It may have been deleted by another user. https://server.org/it-test/jpaugh/awesomeSite

I'm using the following code. Am I doing this correctly?

var context = SP.ClientContext.get_current()
var fields = context.get_web().get_fields();
var formatted = "<field Name='ProgramName' DisplayName='Program Name' Required='true'"
   + " Group='Awesome' Type='Text' MaxLength='100'></field>";
fields.addFieldAsXml(formatted, false, SP.AddFieldOptions.addFieldCheckDisplayName);
context.executeQueryAsync(success, failure);


function success() {
    console.log("Request success");
}
function failure(sender, args) {
    console.error("Request failed: " + args.get_message());
}

1 Answer 1

1

The issue lies with the case of the <field> and </field> tag.

It should be <Field> and </Field>. Its case sensitive.

Also, to make it required, it needs to TRUE.

So, try the below code. Works at my end :

var context = SP.ClientContext.get_current()
var fields = context.get_web().get_fields();
var formatted = "<Field Name='ProgramName' DisplayName='Program Name' Required='TRUE'"
   + " Group='Awesome' Type='Text' MaxLength='100'></Field>";
fields.addFieldAsXml(formatted, false, SP.AddFieldOptions.addFieldCheckDisplayName);
context.executeQueryAsync(success, failure);


function success() {
    console.log("Request success");
}
function failure(sender, args) {
    console.error("Request failed: " + args.get_message());
}

Reference Field element

0

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.