isMemberOfGroup for a specific User and not the current one
Hi skybow
I want to use "isMemberOfGroup('<Group') für a specific User and not for the current user on the @User Object.
Is there a possibility within skybow to check if a specific user (from a PeoplePickerField) is MemberOfGroup XY (and not the current One).
With custom code it would work, but I like to use Ootb and I mean, the isMemberOfGroup function is already there, but only for current.
-
Hi Joel
There is no built-in function or hidden functionality to check this so far.
The technical possibility of this new function was in discussion in our development team and needs some more investigation.
Since these functionality is all running in client context it's needed to check if these queries would work for all users... and some more research is needed before starting an implementation.You can expect further updates about this topic here.
0 -
Hi gruetterj,
Our investigations have shown that it would be technically possible and that it is possible to read out the group memberships of other users even as a read-only user.
Currently this can be achieved via the following script.//jQuery.Deferred used to wait while it checkingvar deferrer = jQuery.Deferred();
//Name of Group to check
var groupName = "Group Name";var context = new SP.ClientContext.get_current();var web = context.get_web();//Use People or Group Field and take ID of user in itvar user = web.get_siteUsers().getById([[UserFieldSingle.ID]]);context.load(user);var groups = user.get_groups();context.load(groups);context.executeQueryAsync(Function.createDelegate(null, loadUserGroupsSuccess),Function.createDelegate(null, loadUserGroupsFail));function loadUserGroupsSuccess() {var gEnumerator = groups.getEnumerator();var belongstoSpecifiedgroup = false;while (gEnumerator.moveNext()) {var currGroup = gEnumerator.get_current();if (currGroup.get_title().toLowerCase() == groupName.toLocaleLowerCase()) {belongstoSpecifiedgroup = true;break;}}//Resolve deferred with valuedeferrer.resolve(belongstoSpecifiedgroup);}function loadUserGroupsFail(sender,args) {//reject deferred with errordeferrer.reject(args.get_message());}In order to include it as an easy-to-use function in our expressions, I must ask you, to add this as an idea and give your vote for it.
https://my.skybow.com/hc/en-us/community/topics/360000696439-Solution-Studio-Online-Ideas
2 -
Hi Thanks for the workaround.
I tried your code, but I'm always getting "undefined" as a result. I'm using it in the Visible Expression of a Command Bar Action. Any idea how to fix or where the problem could be?Also, I could not find this request in the Online Ideas section. Should I open it instead (i would find this very helpful)
0 -
Hi Matthias
Thanks for your initial code, everything was fine with it, and i don't know where my error came from... So adapt the code a little in order to allow multiple Groups (array) and also check multiple Users.
In combination with the Validation Expression of a field it now solves perfectly our use case. Thanks for your help!//jQuery.Deferred used to wait while it checking
var deferrer = jQuery.Deferred();
//Name of Group to check
var groupName = ["group1","grop2","group3"];
var context = new SP.ClientContext.get_current();
var web = context.get_web();
//Use People or Group Field and take ID of user in it
var user = web.get_siteUsers().getById([[Signer.ID]]);
var user2 = web.get_siteUsers().getById([[Approver.ID]]);
context.load(user);
var groups = user.get_groups();
context.load(groups);
context.executeQueryAsync(
Function.createDelegate(null, loadUserGroupsSuccess),
Function.createDelegate(null, loadUserGroupsFail)
);
context.load(user2);
var groups = user.get_groups();
context.load(groups);
context.executeQueryAsync(
Function.createDelegate(null, loadUserGroupsSuccess),
Function.createDelegate(null, loadUserGroupsFail)
);
function loadUserGroupsSuccess() {
var gEnumerator = groups.getEnumerator();
var belongstoSpecifiedgroup = false;
while (gEnumerator.moveNext()) {
var currGroup = gEnumerator.get_current();
if (groupName.includes(currGroup.get_title().toLowerCase()) == true) {
belongstoSpecifiedgroup = true;
break;
}
}
//Resolve deferred with value
deferrer.resolve(belongstoSpecifiedgroup);
}
function loadUserGroupsFail(sender,args) {
//reject deferred with error
deferrer.reject(args.get_message());
}
return deferrer.promise();1 -
Hi Andreas Teixeira
thanks a lot for your feedback and for sharing your solution with us!
Kind regards
Matthias
0
Please sign in to leave a comment.
Comments
5 comments