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,
-
- 'use strict';
-
- var context = SP.ClientContext.get_current();
-
- var hostWebURL, appWebURL;
-
- $(document).ready(function()
- {
-
- hostWebURL = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));
- appWebURL = decodeURIComponent(manageQueryStringParameter('SPAppWebUrl'));
-
- ChangeGroupName();
- });
-
- 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 value
function 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];
}
}
}
Summary
In this blog we have explored how to rename the SharePoint user group using JavaScript Object Model.