Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm working on a workflow project, where I have to get all the users in the Approvers group. In order to get the approvals group, I run the following code:

SPGroup approvals = SPContext.Current.Web.Groups["Approvers"];

However, I noticed that you can change the group name, in which case, this code would break. So, I discovered the Membership group ID for that group, which is 9. However, i'm not sure if that will be consistent across SharePoint installations. Could anyone confirm this? If not, is there a better way to get the Approvers group.

Many thanks!

share|improve this question

2 Answers 2

I will not vouch for any consistency here because I don't know whether or not that value remains consistent across installations. What I can provide is a work around that I have been using. Since I don't know under what context you are trying to accomplish this you may have to alter the solution slightly.

Since you are writing code behind I can assume that you are doing a custom solution. Generally when I do a custom solution I have either a configuration list or utilize the property bag when it comes to retrieving things that are dynamic with a lesser known unique identifier (Group IDs vs Group Name, List Guids vs List Name, etc.). Generally I will write the value I need to the property bag or configuration list on the feature activated event though this could be done via powershell, console app, or whatever works best for you.

In this particular instance you would want to store the group ID since we know it will not be changing. Once you've got the value stored some place on the site you want to use it on you can retrieve it whenever you want with the only real worry you have to have is that the group no longer exists.

share|improve this answer
    
Yes, that's the only thing I'm currently concerned about: the only real worry you have to have is that the group no longer exists. –  Pathachiever11 Jun 8 '12 at 23:32
    
And that's why its configurable. If the group no longer exists, you simply specify a new group in its place. –  ToddersLegrande Jun 10 '12 at 3:24
    
I agree, but that is not upto me...For instance, what if the site has a different approver's group, how would I know that out of 10 groups, which one is the approvers group... –  Pathachiever11 Jun 12 '12 at 18:38
2  
The problem you are presenting here is that someone is arbitrarily choosing a group to be the approvers group. If there is no logic behind which one was chosen as the approvers group how do you expect to be able to determine that in code? If the users break the rules and delete THE approvers group you preconfigured they'll complain the application isn't working in which you can find the source of the problem through proper logging, etc. and ask them which group it should be and why they deleted the old group. –  ToddersLegrande Jun 12 '12 at 19:51
2  
The approvers group is just a default group that is given a certain set of permissions out of the box. You could create any group to be like this or you could even change the approvers group to NOT have approve permissions. It's just a group that is created for you to help save you time. –  ToddersLegrande Jun 15 '12 at 20:38

If you have such concerns, I suggest don't hard code the approver group at all. Use the Workflow association form to let the user specify the approver group for a particular workflow. Recently I have a similiar requirement from my client, they want me to hard code the approver group too. The approver group will be in the format of document library + "Approver". Instead I created the association form and they seemed happy about it. Hope this helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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