Skip to main content
replaced http://sharepoint.stackexchange.com/ with https://sharepoint.stackexchange.com/
Source Link

When getting field by title, it doesn't work. You should get it byInternalNameOrTitle. The reason is, it's SharePoint! This is why it is so hated and this is why it is so loved :)

This code piece worked for me (while if I replaced getByInternalNameOrTitle to getByTitle - I get the same error as you do):

var context=SP.ClientContext.get_current();
var field = context.get_web().get_availableFields().getByInternalNameOrTitle("Priority");
var fieldChoice = context.castTo(field, SP.FieldChoice);
context.load(fieldChoice);
context.executeQueryAsync(function() {
  var choices = fieldChoice.get_choices();
  console.log(choices);
},
function(s,a){
  alert('ERR: ' + a.get_message());
});

enter image description here

Also, this question is sort of duplicate of this one:

So don't forget to upvote Ryan's answer ;)

Though I think it doesn't hurt to emphasize that getByTitle doesn't work in this case.

When getting field by title, it doesn't work. You should get it byInternalNameOrTitle. The reason is, it's SharePoint! This is why it is so hated and this is why it is so loved :)

This code piece worked for me (while if I replaced getByInternalNameOrTitle to getByTitle - I get the same error as you do):

var context=SP.ClientContext.get_current();
var field = context.get_web().get_availableFields().getByInternalNameOrTitle("Priority");
var fieldChoice = context.castTo(field, SP.FieldChoice);
context.load(fieldChoice);
context.executeQueryAsync(function() {
  var choices = fieldChoice.get_choices();
  console.log(choices);
},
function(s,a){
  alert('ERR: ' + a.get_message());
});

enter image description here

Also, this question is sort of duplicate of this one:

So don't forget to upvote Ryan's answer ;)

Though I think it doesn't hurt to emphasize that getByTitle doesn't work in this case.

When getting field by title, it doesn't work. You should get it byInternalNameOrTitle. The reason is, it's SharePoint! This is why it is so hated and this is why it is so loved :)

This code piece worked for me (while if I replaced getByInternalNameOrTitle to getByTitle - I get the same error as you do):

var context=SP.ClientContext.get_current();
var field = context.get_web().get_availableFields().getByInternalNameOrTitle("Priority");
var fieldChoice = context.castTo(field, SP.FieldChoice);
context.load(fieldChoice);
context.executeQueryAsync(function() {
  var choices = fieldChoice.get_choices();
  console.log(choices);
},
function(s,a){
  alert('ERR: ' + a.get_message());
});

enter image description here

Also, this question is sort of duplicate of this one:

So don't forget to upvote Ryan's answer ;)

Though I think it doesn't hurt to emphasize that getByTitle doesn't work in this case.

Source Link
Andrey Markeev
  • 16.3k
  • 3
  • 41
  • 70

When getting field by title, it doesn't work. You should get it byInternalNameOrTitle. The reason is, it's SharePoint! This is why it is so hated and this is why it is so loved :)

This code piece worked for me (while if I replaced getByInternalNameOrTitle to getByTitle - I get the same error as you do):

var context=SP.ClientContext.get_current();
var field = context.get_web().get_availableFields().getByInternalNameOrTitle("Priority");
var fieldChoice = context.castTo(field, SP.FieldChoice);
context.load(fieldChoice);
context.executeQueryAsync(function() {
  var choices = fieldChoice.get_choices();
  console.log(choices);
},
function(s,a){
  alert('ERR: ' + a.get_message());
});

enter image description here

Also, this question is sort of duplicate of this one:

So don't forget to upvote Ryan's answer ;)

Though I think it doesn't hurt to emphasize that getByTitle doesn't work in this case.