2

I am trying to get a list of a user's Jive SBS permission groups. How would this be done with jQuery?

Ivan
  • 549
  • 3
  • 11
  • Please consider showing examples of what you have already tried in order to show effort towards a solution rather than crowdsourcing code. – clesiemo3 Aug 03 '15 at 15:15
  • 1
    I was asked this question over email, so I just ported it here to help others. The answer is below. – Ivan Aug 03 '15 at 15:19

1 Answers1

3

Using the Jive v3 API this isn't so hard. The worst part is that you have to sanitize the result from Jive to make it valid JSON. Thankfully you can use Datafilter.

// We will use this as our data filter in the AJAX call

sanitizeJiveJsonResponse: function(response){
    return response.replace("throw 'allowIllegalResourceCall is false.';", '');
},

// You can get the logged in user id from the __jive variable. Including any sort     
// of JS in a Jive widget or tile will cause that code to run from an iframe, so      
// we're using window.parent to reference it

var userid = window.parent._jive_current_user.ID;
if(typeof userid == 'undefined'){
    // Error stuff here
}

$.ajax({

    url: '/api/core/v3/people/' + userid + '/securityGroups',
    context: document.body,
    dataType: 'json',
    dataFilter: function (data, type) {
        return sanitizeJiveJsonResponse(data);
    }

    }).done(function(result) {
        // Your success code here...
    });
};

Hope this helps!

Ivan
  • 549
  • 3
  • 11