Showing posts with label SPServices. Show all posts
Showing posts with label SPServices. Show all posts

Monday, March 17, 2014

Update UserProfile properties in using SPServices in SharePoint

I got a requirement to update the User Profile properties for one of my client. We have only option to do that using SPServices because they are not allowing any server side code. In SPServices we can directly update the user profile services using “ModifyUserPropertyByAccountName” method. By passing current logged-in user account to the method we can update the user profile properties using SPServices. I have found the following code from here (http://azzu-sheikh.blogspot.in/2014/01/update-user-profile-property-through.html)to update the user profile service.

function updateUserProfileProperty(currentLoggedInUser, propertyName, propertyValue) {
   var propertyData = "<PropertyData>" +
  "<IsPrivacyChanged>false</IsPrivacyChanged>" +
  "<IsValueChanged>true</IsValueChanged>" +
  "<Name>" + propertyName + "</Name>" +
  "<Privacy>NotSet</Privacy>" +
  "<Values><ValueData><Value xsi:type=\"xsd:string\">" + propertyValue + "</Value></ValueData></Values>" +
  "</PropertyData>";

   $().SPServices({
       operation: "ModifyUserPropertyByAccountName",
       async: false,
       webURL: "/",
       accountName: currentLoggedInUser,
       newData: propertyData,
       completefunc: function (xData, Status) {
           var result = $(xData.responseXML);
           if (Status == "success") {
              //do update action
           }
       }
   });
}


We can change the user property details by getting property data in to the method and passing the current logged-in user account details as shown the code above.

Wednesday, March 12, 2014

Check current logged-in user having permissions to specific group in SharePoint SPServices

We can check the groups for current logged-in user from SPServices code using “GetGroupCollectionFromUser” opration. Before the we have to download and add folowing files. Javascript 1.7.1.js and JQuery.SpServices-0.7.1a.min.js

Following script will used to get the user group details

$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function (xData, Status) {
var count = 0;
$(xData.responseXML).find("Group").each(function () {
if ($(this).attr("Name") == "Group Name") 
count++; 
}
 }); 
if (count == 0) {
// do some action
}
else {
// do some action
}
}
});