Skip to main content
Code was having errors
Source Link
DvG
  • 2.3k
  • 2
  • 15
  • 31
   <script language="javascript" type="text/javascript">
    function clickMe() {          
    var clientContext = new SP.ClientContext.get_current(); 
    siteGroups = clientContext.get_web().get_siteGroups();
    clientContext.load(siteGroups);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    }        
    function onQuerySucceeded() {
    var ifGroupExist = false;
    for (var i =0 ; i < siteGroups.get_count(); i++)
        {
           if("my_particular_group_name" == siteGroups.itemAt(i).get_title()){
                ifGroupExist = true;                    
           }
        }
    // create SP group if it does not exist
    if(!ifGroupExist) { createSPGroup();}
   }
    function onQueryFailed() {    
        alert('Request failed');
    }
     
  
    
    function createSPGroup()
    {
        var web = context.get_web();      
        var groupCollection = web.get_siteGroups();  
        // Create Group information for Group  
        var newGRP = new SP.GroupCreationInformation();  
        newGRP.set_title("your_particular_Group");  
        newGRP.set_description("sample description");  
      
        var currentUser = web.get_currentUser();  
        context.load(currentUser);  
      
        context.load(web, 'Title', 'HasUniqueRoleAssignments');  
        context.executeQueryAsync(function() {  
      
        if (!web.get_hasUniqueRoleAssignments()) {  
            web.breakRoleInheritance(true, false);  
        }  
      
        //add group to site gorup collection  
        var newCreateGroup = groupCollection.add(newGRP);  
        //Role Definition   
        var rolDef = web.get_roleDefinitions().getByName("Edit");  
        var rolDefColl = SP.RoleDefinitionBindingCollection.newObject(context);  
        rolDefColl.add(rolDef);  
    
        // Get the RoleAssignmentCollection for the target web.  
        var roleAssignments = web.get_roleAssignments();  
        // assign the group to the new RoleDefinitionBindingCollection.  
        roleAssignments.add(newCreateGroup, rolDefColl);  
        //Set group properties  
        newCreateGroup.set_allowMembersEditMembership(true);  
        newCreateGroup.set_onlyAllowMembersViewMembership(false);  
        newCreateGroup.update();  
        context.load(newCreateGroup);            
        context.executeQueryAsync(success, fail);       
    },
   function success() {  
             alert("Successfully created group: your_particular_Group");   
   }        
    function fail(src, info) {  
        alert("Failed to create group:" + info.get_message()group");  
    });
}
        </script>
   <script language="javascript" type="text/javascript">
    function clickMe() {          
    var clientContext = new SP.ClientContext.get_current(); 
    siteGroups = clientContext.get_web().get_siteGroups();
    clientContext.load(siteGroups);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    }        
    function onQuerySucceeded() {
    var ifGroupExist = false;
    for (var i =0 ; i < siteGroups.get_count(); i++)
        {
           if("my_particular_group_name" == siteGroups.itemAt(i).get_title()){
                ifGroupExist = true;                    
           }
        }
    // create SP group if it does not exist
    if(!ifGroupExist) { createSPGroup();}
   }
    function onQueryFailed() {    
        alert('Request failed');
    }
     
  
    
    function createSPGroup(){
        var web = context.get_web();      
        var groupCollection = web.get_siteGroups();  
        // Create Group information for Group  
        var newGRP = new SP.GroupCreationInformation();  
        newGRP.set_title("your_particular_Group");  
        newGRP.set_description("sample description");  
      
        var currentUser = web.get_currentUser();  
        context.load(currentUser);  
      
        context.load(web, 'Title', 'HasUniqueRoleAssignments');  
        context.executeQueryAsync(function() {  
      
        if (!web.get_hasUniqueRoleAssignments()) {  
            web.breakRoleInheritance(true, false);  
        }  
      
        //add group to site gorup collection  
        var newCreateGroup = groupCollection.add(newGRP);  
        //Role Definition   
        var rolDef = web.get_roleDefinitions().getByName("Edit");  
        var rolDefColl = SP.RoleDefinitionBindingCollection.newObject(context);  
        rolDefColl.add(rolDef);  
    
        // Get the RoleAssignmentCollection for the target web.  
        var roleAssignments = web.get_roleAssignments();  
        // assign the group to the new RoleDefinitionBindingCollection.  
        roleAssignments.add(newCreateGroup, rolDefColl);  
        //Set group properties  
        newCreateGroup.set_allowMembersEditMembership(true);  
        newCreateGroup.set_onlyAllowMembersViewMembership(false);  
        newCreateGroup.update();  
        context.load(newCreateGroup);            
        context.executeQueryAsync(success, fail);       
    },        
    function fail(src, info) {  
        alert("Failed to create group:" + info.get_message());  
    });
}
        </script>
   <script language="javascript" type="text/javascript">
    function clickMe() {          
    var clientContext = new SP.ClientContext.get_current(); 
    siteGroups = clientContext.get_web().get_siteGroups();
    clientContext.load(siteGroups);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    }        
    function onQuerySucceeded() {
    var ifGroupExist = false;
    for (var i =0 ; i < siteGroups.get_count(); i++)
        {
           if("my_particular_group_name" == siteGroups.itemAt(i).get_title()){
                ifGroupExist = true;                    
           }
        }
    // create SP group if it does not exist
    if(!ifGroupExist) { createSPGroup();}
   }
    function onQueryFailed() {    
        alert('Request failed');
    }    
    
    function createSPGroup()
    {
        var web = context.get_web();      
        var groupCollection = web.get_siteGroups();  
        // Create Group information for Group  
        var newGRP = new SP.GroupCreationInformation();  
        newGRP.set_title("your_particular_Group");  
        newGRP.set_description("sample description");  
      
        var currentUser = web.get_currentUser();  
        context.load(currentUser);  
      
        context.load(web, 'Title', 'HasUniqueRoleAssignments');  
        context.executeQueryAsync(function() {  
      
        if (!web.get_hasUniqueRoleAssignments()) {  
            web.breakRoleInheritance(true, false);  
        }  
      
        //add group to site gorup collection  
        var newCreateGroup = groupCollection.add(newGRP);  
        //Role Definition   
        var rolDef = web.get_roleDefinitions().getByName("Edit");  
        var rolDefColl = SP.RoleDefinitionBindingCollection.newObject(context);  
        rolDefColl.add(rolDef);  
    
        // Get the RoleAssignmentCollection for the target web.  
        var roleAssignments = web.get_roleAssignments();  
        // assign the group to the new RoleDefinitionBindingCollection.  
        roleAssignments.add(newCreateGroup, rolDefColl);  
        //Set group properties  
        newCreateGroup.set_allowMembersEditMembership(true);  
        newCreateGroup.set_onlyAllowMembersViewMembership(false);  
        newCreateGroup.update();  
        context.load(newCreateGroup);            
        context.executeQueryAsync(success, fail);       
    }
   function success() {  
             alert("Successfully created group: your_particular_Group");   
   }        
    function fail() {  
        alert("Failed to create group");  
    }
        </script>
   <script language="javascript" type="text/javascript">
    function clickMe() {          
    var clientContext = new SP.ClientContext.get_current(); 
    siteGroups = clientContext.get_web().get_siteGroups();
    clientContext.load(siteGroups);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    }        
    function onQuerySucceeded() {
    var ifGroupExist = false;
    for (var i =0 ; i < siteGroups.get_count(); i++)
        {
           if("my_particular_group_name" == siteGroups.itemAt(i).get_title()){
                ifGroupExist = true;                    
           }
        }
    // create SP group if it does not exist
    if(!ifGroupExist) { createSPGroup();}
   }
    function onQueryFailed() {    
        alert('Request failed');
    }
    
  
    
    function createSPGroup(){
        var web = context.get_web();      
        var groupCollection = web.get_siteGroups();  
        // Create Group information for Group  
        var newGRP = new SP.GroupCreationInformation();  
        newGRP.set_title("your_particular_Group");  
        newGRP.set_description("sample description");  
      
        var currentUser = web.get_currentUser();  
        context.load(currentUser);  
      
        context.load(web, 'Title', 'HasUniqueRoleAssignments');  
        context.executeQueryAsync(function() {  
      
        if (!web.get_hasUniqueRoleAssignments()) {  
            web.breakRoleInheritance(true, false);  
        }  
      
        //add group to site gorup collection  
        var newCreateGroup = groupCollection.add(newGRP);  
        //Role Definition   
        var rolDef = web.get_roleDefinitions().getByName("Edit");  
        var rolDefColl = SP.RoleDefinitionBindingCollection.newObject(context);  
        rolDefColl.add(rolDef);  
    
        // Get the RoleAssignmentCollection for the target web.  
        var roleAssignments = web.get_roleAssignments();  
        // assign the group to the new RoleDefinitionBindingCollection.  
        roleAssignments.add(newCreateGroup, rolDefColl);  
        //Set group properties  
        newCreateGroup.set_allowMembersEditMembership(true);  
        newCreateGroup.set_onlyAllowMembersViewMembership(false);  
        newCreateGroup.update();  
        context.load(newCreateGroup);            
        context.executeQueryAsync(success, fail);       
    }
    
    function success() {  
        alert("Successfully created group: your_particular_Group");,  
     },  
    function fail(src, info) {  
        alert("Failed to create group:" + info.get_message());  
    });
}
        </script>
   <script language="javascript" type="text/javascript">
    function clickMe() {          
    var clientContext = new SP.ClientContext.get_current(); 
    siteGroups = clientContext.get_web().get_siteGroups();
    clientContext.load(siteGroups);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    }        
    function onQuerySucceeded() {
    var ifGroupExist = false;
    for (var i =0 ; i < siteGroups.get_count(); i++)
        {
           if("my_particular_group_name" == siteGroups.itemAt(i).get_title()){
                ifGroupExist = true;                    
           }
        }
    // create SP group if it does not exist
    if(!ifGroupExist) { createSPGroup();}
   }
    function onQueryFailed() {    
        alert('Request failed');
    }
    
  
    
    function createSPGroup(){
        var web = context.get_web();      
        var groupCollection = web.get_siteGroups();  
        // Create Group information for Group  
        var newGRP = new SP.GroupCreationInformation();  
        newGRP.set_title("your_particular_Group");  
        newGRP.set_description("sample description");  
      
        var currentUser = web.get_currentUser();  
        context.load(currentUser);  
      
        context.load(web, 'Title', 'HasUniqueRoleAssignments');  
        context.executeQueryAsync(function() {  
      
        if (!web.get_hasUniqueRoleAssignments()) {  
            web.breakRoleInheritance(true, false);  
        }  
      
        //add group to site gorup collection  
        var newCreateGroup = groupCollection.add(newGRP);  
        //Role Definition   
        var rolDef = web.get_roleDefinitions().getByName("Edit");  
        var rolDefColl = SP.RoleDefinitionBindingCollection.newObject(context);  
        rolDefColl.add(rolDef);  
    
        // Get the RoleAssignmentCollection for the target web.  
        var roleAssignments = web.get_roleAssignments();  
        // assign the group to the new RoleDefinitionBindingCollection.  
        roleAssignments.add(newCreateGroup, rolDefColl);  
        //Set group properties  
        newCreateGroup.set_allowMembersEditMembership(true);  
        newCreateGroup.set_onlyAllowMembersViewMembership(false);  
        newCreateGroup.update();  
        context.load(newCreateGroup);            
        context.executeQueryAsync(success, fail);       
    }
    
    function success() {  
        alert("Successfully created group: your_particular_Group");  
     },  
    function fail(src, info) {  
        alert("Failed to create group:" + info.get_message());  
    });
    </script>
   <script language="javascript" type="text/javascript">
    function clickMe() {          
    var clientContext = new SP.ClientContext.get_current(); 
    siteGroups = clientContext.get_web().get_siteGroups();
    clientContext.load(siteGroups);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    }        
    function onQuerySucceeded() {
    var ifGroupExist = false;
    for (var i =0 ; i < siteGroups.get_count(); i++)
        {
           if("my_particular_group_name" == siteGroups.itemAt(i).get_title()){
                ifGroupExist = true;                    
           }
        }
    // create SP group if it does not exist
    if(!ifGroupExist) { createSPGroup();}
   }
    function onQueryFailed() {    
        alert('Request failed');
    }
    
  
    
    function createSPGroup(){
        var web = context.get_web();      
        var groupCollection = web.get_siteGroups();  
        // Create Group information for Group  
        var newGRP = new SP.GroupCreationInformation();  
        newGRP.set_title("your_particular_Group");  
        newGRP.set_description("sample description");  
      
        var currentUser = web.get_currentUser();  
        context.load(currentUser);  
      
        context.load(web, 'Title', 'HasUniqueRoleAssignments');  
        context.executeQueryAsync(function() {  
      
        if (!web.get_hasUniqueRoleAssignments()) {  
            web.breakRoleInheritance(true, false);  
        }  
      
        //add group to site gorup collection  
        var newCreateGroup = groupCollection.add(newGRP);  
        //Role Definition   
        var rolDef = web.get_roleDefinitions().getByName("Edit");  
        var rolDefColl = SP.RoleDefinitionBindingCollection.newObject(context);  
        rolDefColl.add(rolDef);  
    
        // Get the RoleAssignmentCollection for the target web.  
        var roleAssignments = web.get_roleAssignments();  
        // assign the group to the new RoleDefinitionBindingCollection.  
        roleAssignments.add(newCreateGroup, rolDefColl);  
        //Set group properties  
        newCreateGroup.set_allowMembersEditMembership(true);  
        newCreateGroup.set_onlyAllowMembersViewMembership(false);  
        newCreateGroup.update();  
        context.load(newCreateGroup);            
        context.executeQueryAsync(success, fail);       
    },        
    function fail(src, info) {  
        alert("Failed to create group:" + info.get_message());  
    });
}
        </script>
added 22 characters in body
Source Link
DvG
  • 2.3k
  • 2
  • 15
  • 31
   <script language="javascript" type="text/javascript">
    function clickMe() {          
    var clientContext = new SP.ClientContext.get_current(); 
    siteGroups = clientContext.get_web().get_siteGroups();
    clientContext.load(siteGroups);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    }
     var ifGroupExist = false; 
    function onQuerySucceeded() {
    var ifGroupExist = false;
    for (var i =0 ; i < siteGroups.get_count(); i++)
        {
           if("my_particular_group_name" == siteGroups.itemAt(i).get_title()){
                ifGroupExist = true;                    
           }
        }
    }
  // create functionSP onQueryFailed()group {if it does not exist
      if(!ifGroupExist) { alertcreateSPGroup('Request failed');}
    }
    function onQueryFailed() {    
    // create SP group ifalert('Request itfailed');
 does not exist }
    if(!ifGroupExist) 
 { createSPGroup();}
    
    function createSPGroup(){
        var web = context.get_web();      
        var groupCollection = web.get_siteGroups();  
        // Create Group information for Group  
        var newGRP = new SP.GroupCreationInformation();  
        newGRP.set_title("your_particular_Group");  
        newGRP.set_description("sample description");  
      
        var currentUser = web.get_currentUser();  
        context.load(currentUser);  
      
        context.load(web, 'Title', 'HasUniqueRoleAssignments');  
        context.executeQueryAsync(function() {  
      
        if (!web.get_hasUniqueRoleAssignments()) {  
            web.breakRoleInheritance(true, false);  
        }  
      
        //add group to site gorup collection  
        var newCreateGroup = groupCollection.add(newGRP);  
        //Role Definition   
        var rolDef = web.get_roleDefinitions().getByName("Edit");  
        var rolDefColl = SP.RoleDefinitionBindingCollection.newObject(context);  
        rolDefColl.add(rolDef);  
    
        // Get the RoleAssignmentCollection for the target web.  
        var roleAssignments = web.get_roleAssignments();  
        // assign the group to the new RoleDefinitionBindingCollection.  
        roleAssignments.add(newCreateGroup, rolDefColl);  
        //Set group properties  
        newCreateGroup.set_allowMembersEditMembership(true);  
        newCreateGroup.set_onlyAllowMembersViewMembership(false);  
        newCreateGroup.update();  
        context.load(newCreateGroup);            
        context.executeQueryAsync(success, fail);       
    }
    
    function success() {  
        alert("Successfully created group: your_particular_Group");  
    },  
    function fail(src, info) {  
        alert("Failed to create group:" + info.get_message());  
    });
    </script>
   <script language="javascript" type="text/javascript">
    function clickMe() {   
    var clientContext = new SP.ClientContext.get_current(); 
    siteGroups = clientContext.get_web().get_siteGroups();
    clientContext.load(siteGroups);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    }
     var ifGroupExist = false;
    function onQuerySucceeded() {
    for (var i =0 ; i < siteGroups.get_count(); i++)
        {
           if("my_particular_group_name" == siteGroups.itemAt(i).get_title()){
                ifGroupExist = true;                    
           }
        }
    }
    function onQueryFailed() {    
        alert('Request failed');
    }
    
    // create SP group if it does not exist
    if(!ifGroupExist) { createSPGroup();}
    
    function createSPGroup(){
        var web = context.get_web();      
        var groupCollection = web.get_siteGroups();  
        // Create Group information for Group  
        var newGRP = new SP.GroupCreationInformation();  
        newGRP.set_title("your_particular_Group");  
        newGRP.set_description("sample description");  
      
        var currentUser = web.get_currentUser();  
        context.load(currentUser);  
      
        context.load(web, 'Title', 'HasUniqueRoleAssignments');  
        context.executeQueryAsync(function() {  
      
        if (!web.get_hasUniqueRoleAssignments()) {  
            web.breakRoleInheritance(true, false);  
        }  
      
        //add group to site gorup collection  
        var newCreateGroup = groupCollection.add(newGRP);  
        //Role Definition   
        var rolDef = web.get_roleDefinitions().getByName("Edit");  
        var rolDefColl = SP.RoleDefinitionBindingCollection.newObject(context);  
        rolDefColl.add(rolDef);  
    
        // Get the RoleAssignmentCollection for the target web.  
        var roleAssignments = web.get_roleAssignments();  
        // assign the group to the new RoleDefinitionBindingCollection.  
        roleAssignments.add(newCreateGroup, rolDefColl);  
        //Set group properties  
        newCreateGroup.set_allowMembersEditMembership(true);  
        newCreateGroup.set_onlyAllowMembersViewMembership(false);  
        newCreateGroup.update();  
        context.load(newCreateGroup);            
        context.executeQueryAsync(success, fail);       
    }
    
    function success() {  
        alert("Successfully created group: your_particular_Group");  
    },  
    function fail(src, info) {  
        alert("Failed to create group: + info.get_message());  
    });
    </script>
   <script language="javascript" type="text/javascript">
    function clickMe() {          
    var clientContext = new SP.ClientContext.get_current(); 
    siteGroups = clientContext.get_web().get_siteGroups();
    clientContext.load(siteGroups);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    }        
    function onQuerySucceeded() {
    var ifGroupExist = false;
    for (var i =0 ; i < siteGroups.get_count(); i++)
        {
           if("my_particular_group_name" == siteGroups.itemAt(i).get_title()){
                ifGroupExist = true;                    
           }
        }
    // create SP group if it does not exist
    if(!ifGroupExist) { createSPGroup();}
   }
    function onQueryFailed() {    
        alert('Request failed');
    }
     
  
    
    function createSPGroup(){
        var web = context.get_web();      
        var groupCollection = web.get_siteGroups();  
        // Create Group information for Group  
        var newGRP = new SP.GroupCreationInformation();  
        newGRP.set_title("your_particular_Group");  
        newGRP.set_description("sample description");  
      
        var currentUser = web.get_currentUser();  
        context.load(currentUser);  
      
        context.load(web, 'Title', 'HasUniqueRoleAssignments');  
        context.executeQueryAsync(function() {  
      
        if (!web.get_hasUniqueRoleAssignments()) {  
            web.breakRoleInheritance(true, false);  
        }  
      
        //add group to site gorup collection  
        var newCreateGroup = groupCollection.add(newGRP);  
        //Role Definition   
        var rolDef = web.get_roleDefinitions().getByName("Edit");  
        var rolDefColl = SP.RoleDefinitionBindingCollection.newObject(context);  
        rolDefColl.add(rolDef);  
    
        // Get the RoleAssignmentCollection for the target web.  
        var roleAssignments = web.get_roleAssignments();  
        // assign the group to the new RoleDefinitionBindingCollection.  
        roleAssignments.add(newCreateGroup, rolDefColl);  
        //Set group properties  
        newCreateGroup.set_allowMembersEditMembership(true);  
        newCreateGroup.set_onlyAllowMembersViewMembership(false);  
        newCreateGroup.update();  
        context.load(newCreateGroup);            
        context.executeQueryAsync(success, fail);       
    }
    
    function success() {  
        alert("Successfully created group: your_particular_Group");  
    },  
    function fail(src, info) {  
        alert("Failed to create group:" + info.get_message());  
    });
    </script>
Source Link
DvG
  • 2.3k
  • 2
  • 15
  • 31
Loading