Posts

Showing posts with the label ECMA Script

SharePoint 2010 Client side script to check if a user is in a SharePoint group

The following script looks in the SharePoint object model if the current users exists in the SharePoint group 'My Group Name'. If the user exists, then the button 'My Button' is hidden: ExecuteOrDelayUntilScriptLoaded(disableControls, "sp.js"); function disableControls() {     clientContext = new SP.ClientContext.get_current();     currentUser = clientContext.get_web().get_currentUser();     clientContext.load(currentUser);     this.collGroup = clientContext.get_web().get_siteGroups();     clientContext.load(collGroup);     clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); } function onQuerySucceeded() {     var groupEnumerator = collGroup.getEnumerator();     while (groupEnumerator.moveNext()) {         var oGroup = groupEnumerator...