Is it possible to retrieve all fields of a list (or default view) through the JavaScript Client Object Model and filter the fields on type (e.g. I only want the Choice fields).
var clientContext = new SP.ClientContext.get_current();
var web = clientContext.get_web();
var list = web.get_lists().getByTitle(listName);
var defaultview = list.getView('00000000-0000-0000-0000-000000000000');
this.listFields = defaultview.get_viewFields();
clientContext.executeQueryAsync(Function.createDelegate(this,
this.onListFieldsQuerySucceeded), Function.createDelegate(this,
this.onListFieldsQueryFailed));
function onListFieldsQuerySucceeded() {
var fieldEnumerator = listFields.getEnumerator();
while (fieldEnumerator.moveNext()) {
var oField = fieldEnumerator.get_current();
...
}
}
Right now I'm getting following exception on listFields.getEnumerator()
Microsoft JScript runtime error: The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
Same problem if I get the fields on the list directly.
this.listFields.getEnumerator()
?