I wrote some code to get the current user groups by CSOM.
function getCurrentUser() {
this.clientContext = new SP.ClientContext.get_current();
this.oWeb = clientContext.get_web();
currentUser = this.oWeb.get_currentUser();
this.clientContext.load(currentUser);
clientContext.load(allGroups);
this.clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededUser), Function.createDelegate(this, this.onQueryFailedUser));
}
function onQuerySucceededUser() {
//debugger;
var groups = currentUser.get_groups();
var groupsEnum = groups.getEnumerator();
while (groupsEnum.moveNext()) {
//handle group
}
}
But I get this 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.
on this line: groups.getEnumerator();
How can I solve it?