Steps for Implementation:
- Get Current Context.
- Get App web URL and Host Web URL from Query string parameter.
- Calling check method in document ready.
- Get web from app context site.
- Get all site group from host web site.
- Get Group by group name
- Set the New Title
- Finally title will be updated with new name on success function
In your JavaScript file write below code,
- // Js code Starts here
- 'use strict';
- //Get Current Context
- var context = SP.ClientContext.get_current();
- //Declaring the variables
- var hostWebURL, appWebURL;
- // this code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
- $(document).ready(function()
- {
- // Get App web URL and Host Web URL from Query string parameter
- hostWebURL = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));
- appWebURL = decodeURIComponent(manageQueryStringParameter('SPAppWebUrl'));
- //Calling check method in document ready
- ChangeGroupName();
- });
- //Change the group name
- function ChangeGroupName()
- {
- var cWeb = appCtx.get_web();
- var collGroup = cWeb.get_siteGroups();
- var oGroup = collGroup.getByName("HFS Managers");
- oGroup.set_title("Test");
- oGroup.update();
- context.load(oGroup);
- context.executeQueryAsync(function()
- {
- alert("success");
- }, function(sender, args)
- {
- alert("Request failed to change the group name " + args.get_message());
- });
- }
- //method for read query string valuefunction manageQueryStringParameter(paramToRetrieve) {var params = document.URL.split("?")[1].split("&");var strParams = "";for (var i = 0; i < params.length; i = i + 1) {var singleParam = params[i].split("=");if (singleParam[0] == paramToRetrieve) {return singleParam[1];}}}
In this blog we have explored how to rename the SharePoint user group using JavaScript Object Model.

Join the conversation! Your thoughts help the community grow.