1

I'm using the following code to get the user permissions on a list item in javascript csom

context = SP.ClientContext.get_current();
              var field = context.castTo(searchtaxonomy_context.get_web().get_availableFields().getByTitle('Business Plan Year'), SP.FieldChoice);
context.load(field,'Choices');
context.executeQueryAsync(function () {
                  var businessplanyearchoices = field.get_choices();},function(s,a){alert(a.get_message())});

I'm getting 'The property or field 'Choices' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. ' in browser console. I'm getting this same error when I load EfffectiveBasePermissions on a list item

  • This occurred because I've used the script tags directly to load sp.js. I removed the script references and used SharePoint on demand script loading by SP.SOD.executeFunc and it worked. The script reference was added in my SharePoint search control template. – sekhar Jan 12 '17 at 10:27
2

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.

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.