Oct 17, 2013

Create groups with JavaScript in SharePoint 2010

All credit goes to Yesh Agrawal for this: http://yeshagrawal.blogspot.com.es/2013/05/create-sp-group-and-assign-permission.html

Here's the code (edited to only create the group, not assign permissions):
<script >
function createSPGroups()
{
var grupos = new Array("group1",
"group2");

//Load new Site
   var currentCTX = new SP.ClientContext();
   var currentWEB  = currentCTX.get_web();

   //Get all groups in site
   var groupCollection = currentWEB.get_siteGroups();

  for(var i = 0; i < grupos.length; i++) { 
   var grupo_nombre = grupos[i];
   var grupo_desc = "Description for "+grupos[i]; 
   // Create Group information for Group
var membersGRP = new SP.GroupCreationInformation();
membersGRP.set_title(grupo_nombre);
membersGRP.set_description(grupo_desc);


//add group
oMembersGRP = currentWEB.get_siteGroups().add(membersGRP);



currentCTX.load(oMembersGRP);
}

//Execute Query
currentCTX.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {
            alert("Done");
}

function onQueryFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
  
<button onclick="createSPGroups(); return false;">Crear grupo</button>

Passing URL parameter to InfoPath and InfoPath rules timing problem

I had this issue trying to pass a URL parameter to a lookup column in InfoPath. Lookup columns are not available as connection targets from the Query webpart so I had to do some roundabout engineering (quite common with InfoPath).

  1. Create a visible field on the form for your incoming parameter (textbox, calculated value, etc). 
  2. Create an action rule that fires when the value of this field changes to do whatever you need to get done (set dropdown or other field). 
  3. Create a formatting rule that always hides this field.