I am using CSOM/JSON to get field data for a list. If I enumerate the list fields I get the field data/object. But if I look for one using getByInternalNameOrTitle
I get the error "The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
".
The code below prints all the fields in that first console.log
but that second one results in an error. What gives?
ExecuteOrDelayUntilScriptLoaded(function()
{
var clientContext = SP.ClientContext.get_current();
var list = clientContext.get_web().get_lists().getByTitle("Meeting Agenda Items");
this.listFields = list.get_fields();
clientContext.load(this.listFields);
clientContext.executeQueryAsync(Function.createDelegate(this, listFieldsLoaded), Function.createDelegate(this, function(){alert("error 1");}));
}, "sp.js");
function listFieldsLoaded()
{
// if i enumerate the list fields this works fine
var fieldEnumerator = listFields.getEnumerator();
while(fieldEnumerator.moveNext())
{
var thisField = fieldEnumerator.get_current();
console.log(thisField.get_internalName());
}
// but if i try to get it by an internal name
// then it does not
var thisField = listFields.getByInternalNameOrTitle("Title");
console.log(thisField.get_internalName());
}