2

Does anyone know if it is possible to programmatically gift badges to users in SharePoint 2013 community sites?

For example I would like to add an event receiver so that whenever anyone is added to the "moderators" group they are giving a badge "moderator".

Thanks.

1

Sure, since members are stored in a regular list (named Community Members) in Community site, you could perform CRUD operations using any API (SSOM, CSOM, REST, SOAP)

Example

How to set Gifted Badge to a Member via CSOM (JavaScript)

var context = new SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle('Community Members');
listItem = list.getItemById(1); //get member item
listItem.set_item('GiftedBadgeLookup', 1); //set Gifted Badge = Expert (Lookup Id = 1)
listItem.update();
context.load(listItem);
context.executeQueryAsync(
   function(){
       console.log('Gifted Badge has been set to: ' + listItem.get_item('GiftedBadgeLookup').get_lookupValue());    
   }, 
   function(sender,args)
   {
      console.log(args.get_message());     
   }
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.