I have got a script which count users in a group:
<script>
var userCollection;
function start(){
var clientContext = new SP.ClientContext();
//Get all groups in site
var groupCollection = clientContext.get_web().get_siteGroups();
// Get the group by name
group = groupCollection.getByName('Sharepoint Group');
//Get all SP Users in SP Group
userCollection = group.get_users();
clientContext.load(userCollection);
//Execute Query
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded1), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded1() {
alert('Liczba użytkowników w grupie PROFlash wynosi: ' +userCollection.get_count());
document.getElementById("count").innerHTML=userCollection.get_count();
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
I tried everything, but it fire me only when I Editing a site, or adding to a site, orremove new user:
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">
var user;
var FlashGroup;
function runCode() {
var clientContext = new SP.ClientContext();
var groupCollection = clientContext.get_web().get_siteGroups();
FlashGroup = groupCollection.getByName('Sharepoint Group');
user = clientContext.get_web().get_currentUser();
var userCollection = FlashGroup.get_users();
userCollection.addUser(user);
clientContext.load(user);
clientContext.load(FlashGroup);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededZapisz), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceededZapisz() {
alert(user.get_title() + " został dodany do " + FlashGroup.get_title());
start();
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
start();
}
</script>
<input id="Button11" type="button" class="ZapiszGrupaPROFlash" value="Zapisz mnie do grupy" onclick="runCode()" />
</asp:Content>
I dont know why I can't use it on page after put start() on page. Please help me.
0 commentaires:
Enregistrer un commentaire