Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

RequestToJoinLeaveEmailSetting is not being set properly.

$
0
0

Hi All,

Using object model I am updating group. The value I am setting in 'RequestToJoinLeaveEmailSetting' field is not showing when using PowerShell command. However, when I am fetching it by the object model, it is showing the new value set to 'RequestToJoinLeaveEmailSetting' field. 

The code I have written in object model is as follows.

                                                        

 public void UpdateGroup(string oldname, string name, string description, bool acptrqst, bool edprmsn, bool mbrrqst, bool viewprmsn, string emailid, string siteUrl, ArrayList newRoles)
        {
            SPTlogger.Debug(string.Format("--> : Inside UpdateGroup(siteCollectionUrl = " + siteUrl + ",groupName = " + name + ")"));
            ArrayList oldRoles = null;
            ArrayList updatedRoles = new ArrayList();
            ArrayList removeRoles = new ArrayList();
            try
            {
                string siteName = siteUrl.Substring(siteUrl.LastIndexOf("/") + 1);
                SPSite Site = new SPSite(siteUrl);
                SPWeb spWeb = Site.OpenWeb();
                SPGroup spGroup = spWeb.SiteGroups[oldname];
                SPRoleCollection roles = spGroup.Roles;
                if (roles != null)
                {
                    oldRoles = new ArrayList();
                    foreach (SPRole role in roles)
                    {
                        oldRoles.Add(role.Name);
                    }
                }
                // here we are comparing the old and new roles to be updated and separating out which roles to be deleted and which is to be updated.
                foreach (string role in oldRoles)
                {
                    if (newRoles.Contains(role))
                    {
                        updatedRoles.Add(role);
                    }
                    else
                    {
                        removeRoles.Add(role);
                    }
                }
                foreach (string rolenames in newRoles)
                {
                    if (!oldRoles.Contains(rolenames))
                    {
                        updatedRoles.Add(rolenames);
                    }
                }
                if (removeRoles != null && removeRoles.Count > 0)
                {
                    SPRoleAssignment roleAssignment = new SPRoleAssignment(spGroup);
                    foreach (string str in removeRoles)
                    {
                        SPRoleDefinition role = spWeb.RoleDefinitions[str];
                        //SPRoleAssignment roleAssignment = new SPRoleAssignment(spGroup);
                        roleAssignment.RoleDefinitionBindings.Remove(role);
                        spWeb.RoleAssignments.Remove(roleAssignment.Member);
                        spWeb.Update();
                    }
                    spWeb.Update();
                }

                if (spGroup != null)
                {
                    spGroup.Description = description;
                    spGroup.Name = name;
                    spGroup.OnlyAllowMembersViewMembership = viewprmsn;
                    spGroup.AllowMembersEditMembership = edprmsn;
                    spGroup.AllowRequestToJoinLeave = mbrrqst;
                    spGroup.AutoAcceptRequestToJoinLeave = acptrqst;
                    //spGroup.RequestToJoinLeaveEmailSetting = emailid;


                    if (updatedRoles != null && updatedRoles.Count > 0)
                    {
                        SPRoleAssignment roleAssignment = new SPRoleAssignment(spGroup);
                        // SPRoleDefinition roleDefinition = spWeb.RoleDefinitions["Contribute"];
                        foreach (string str in updatedRoles)
                        {
                            SPRoleDefinition roleDefinition = spWeb.RoleDefinitions[str];
                            roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
                        }
                        spWeb.RoleAssignments.Add(roleAssignment);
                    }

                    spGroup.RequestToJoinLeaveEmailSetting = emailid;

                    spGroup.Update();
                }
                spWeb.Update();

            }
            catch (Exception ex)
            {
                SPTlogger.Error("-------------------------ERROR-------------------------");
                SPTlogger.Error("Error in UpdateGroup():" + ex.Message);
                throw new Exception(ex.Message);
            }
            finally
            {
                SPTlogger.Debug("<-- : UpdateGroup()");
            }
        }

=======================================

The PowerShell commands I am using are as follows.

$HR = get-spweb http://www.fictionalcompany.com/hr

 $group= $HR.Groups["testGrp"]        

   Using the command below, the RequestToJoinLeaveEmailSetting is being changed , however, that is not fetched by the object model.

 $group.RequestToJoinLeaveEmailSetting="me@domain.com"

Any Idea/Help, how that can be in sync?                                                                                                                                  Thanks in advance!                                                                                                                                                                 Mohak

 


Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>