Hi,
I want to search my web for all the lists that contains a certain checkbox column (get it by name).
Once I have this list, I want to iterate through all of them and get the list items with this column checked.
I got the lists, but when I tried to get the fields - I got an error - the system doesn't recognizes the fields.
To be more specific - in the code I've posted below in method onGetFieldsSuccess I'm getting an error in the first line, as I can't retrieve the enumerator.
In the MSDN I saw how to retrieve list's fields, but there it was a specific list. Is there a way to get the lists who have a specific field?
Any help will be appreciated
<script>ExecuteOrDelayUntilScriptLoaded(showFavorites, "sp.js");
var ctx;
var lists;
function showFavorites()
{
ctx = new SP.ClientContext.get_current();
var web = ctx.get_site().openWeb("/legal");
ctx.load(web);
lists = ctx.get_site().openWeb("/legal").get_lists();
ctx.load(lists);
ctx.executeQueryAsync(Function.createDelegate(this, this.onGetListSuccess), Function.createDelegate(this, this.onFail));
}
var list;
var fields;
function onGetListSuccess(sender, args) {
var listEnumerator = lists.getEnumerator();
while (listEnumerator.moveNext()) {
list = listEnumerator.get_current();
ctx.load(list);
fields = list.get_fields();
ctx.load(fields , 'Include(Title)');
ctx.executeQueryAsync(Function.createDelegate(this, this.onGetFieldsSuccess), Function.createDelegate(this, this.onFail));
}
}
function onGetFieldsSuccess(sender, args)
{
var fieldEnumerator = fields.getEnumerator();
while (fieldEnumerator.moveNext()) {
var field = fieldEnumerator.get_current();
var name = field.get_staticName();
if (name == "MyFavorite") {
alert(list.get_title());
break;
}
}
}
function onFail(sender, args) {
console.log(args.get_message());
}
</script>