Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GetGroupCollectionFromUser

Posted on 2014-12-05
7
Medium Priority
?
518 Views
Last Modified: 2014-12-17
I am trying to use the operation "GetGroupCollectionFromUser" in SPServices but I'm having problems getting the description (About Me) of a SharePoint group.  I notice that the description (About Me)  shows for the default sharepoint groups created for a site but not when I add it.  It always shows empty when I bring the data back but in the UI, there's data.
See image below.

My goal is to determine what SharePoint Group a user belongs to and permission that page accordingly.

GetGroupCollectionFromUser.PNG

Below is my code and the page I have it running on.

<script type="text/javascript" src="http://isaac.issharepoint.com/practice/Assets/jquery-1.8.2.min.js" language="javascript"></script>
<script type="text/javascript" src="http://isaac.issharepoint.com/practice/js/jquery.SPServices-0.7.2.min.js" language="javascript"></script>



<script type="text/javascript">
loggedinUserGroup="";
	$().SPServices({  
	  operation: "GetGroupCollectionFromUser",  
	        userLoginName: $().SPServices.SPGetCurrentUser(),  
	        async: false,
	        webURL: "/",
	        completefunc: function(xData, Status) 
	        { 
		
		console.log(xData.responseXML.xml);
alert(xData.responseXML.xml);
	         $(xData.responseXML).SPFilterNode("z:row").each(function() 
	         {	            
			alert($(this).attr("ows_Name"));
			console.log($(this).attr("ows_Name"));
	         });
	                
	  }
	 });

</script>

Open in new window


Thanks for any help you can provide.
0
Comment
Question by:Isaac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40485721
You have everything you need then  Description is not needed to know what you are doing with a group in CODE.
Description is not held in the same place for user created groups.
there is an article on Stackoverflow that explains it with code here but in short, the description of user created groups is stored in the SiteUserInformationList Builtinfields array

Example in c#
SPGroup g = web.SiteGroups["GroupName"];
SPFieldMultiLineText text = (SPFieldMultiLineText)web.SiteUserInfoList.Fields[SPBuiltInFieldId.Notes];
SPListItem groupItem = web.SiteUserInfoList.GetItemById(g.ID);
groupItem[text.InternalName]= groupDescription;
groupItem.Update();

Open in new window

0
 
LVL 5

Author Comment

by:Isaac
ID: 40485749
Do you have any examples using  spservices & javascript?
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40485751
No but why do you need the DESCRIPTION to do security trimming?  You have the NAME of the groups and thats what you should be working with.  You said "My goal is to determine what SharePoint Group a user belongs to and permission that page accordingly."  for that you don't need any descriptions. And dont forget descriptions can change anytime but have NO Effect on security or group permissions or membership.  Description is just an arbitrary string of chars that has no meaning except what you make of it.
0
 
LVL 5

Author Comment

by:Isaac
ID: 40485890
There are many groups and there are only 5 groups I need to check from:

FinanceDepA
FinanceDepB
FinanceDepC
FinanceDepD
FinanceDepE

The only way to know if I the user is in one of the groups above is to have the name "Finance" in the description and I don't want to hard code the names above in the code because they could be new ones or they could be changed.  I also tried creating a new column and add "Finance" to that but the data for that does not show.
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 2000 total points
ID: 40502627
Using the description is totally the wrong way to go about this.  The group names are all you should be interested in.  Realistically you should be using AD groups and not sharepoint groups and then you can have Groups within Groups.
You can then have an overall IsFinance group that you add all of the individual financeA..E groups into and you only need then to check for the user being in the one single Group, IsFinance.

Forget about descriptions.  Descriptions are not there for security trimming, are not uniform, can contain XML and formatting, are not guaranteed to NOT CHANGE.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question