function AddUserToSPGroup()
{
var vCurrentLoggedUser2=$().SPServices.SPGetCurrentUser({fieldName: "UserName",debug: false});
vCurrentLoggedUser2= "KL\\" + vCurrentLoggedUser2;
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups(57)/users";
$.ajax({
url: requestUri,
type: "POST",
data: JSON.stringify({'__metadata': { 'type': 'SP.User' }, 'LoginName': vCurrentLoggedUser2}),
headers:
{
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#__REQUESTDIGEST").val()
},
success: onSuccess,
error: onError
});//End of ajax
function onSuccess(data)
{
alert('User Added');
}
function onError(error)
{
alert(JSON.stringify(error));
}
}
Using SPServices:-
function SetContributeAccess()
{
var vCurrentLoggedUser=$().SPServices.SPGetCurrentUser({fieldName: "Title",debug: false});
$().SPServices({
operation: "AddUserToGroup",
groupName: "Users",
userLoginName: vCurrentLoggedUser,
async: false,
completefunc: function(data,status){
alert("User added to group");
}// End of completefunc
}); //End of SPServices
}//End of SetContributeAccess
No comments:
Post a Comment