Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Remove/Retrieve all users from the access team template

Posted on by 290

Dear All, 

Is there any way to remove all users from the access team template for a record, I noticed 'RemoveUserFromRecordTeamRequest' works only when we have userid and also it removes only one user, in our case we don't have user guids so wanted to remove all users from the team template is there any way to do so. 

Kind Regards, 

Ashok Jinkala

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Remove/Retrieve all users from the access team template

    Hi Ashok,
    You could use the code below.

        public static void GetAccessTeamMembersAndRemove(IOrganizationService service)
        {
            string strFetchXML = @"<fetch>
                                 <entity name='salesorder' >
                                   <attribute name='name' />
                                       <link-entity name='principalobjectaccess' from='objectid' to='salesorderid' link-type='inner' alias='poa' >
                                          <attribute name='objectid' alias='objectid' />
                                          <link-entity name='team' from='teamid' to='principalid' link-type='inner' >
                                            <link-entity name='teamtemplate' from='teamtemplateid' to='teamtemplateid' >
                                              <attribute name='teamtemplatename' />
                                            </link-entity>
                                            <link-entity name='teammembership' from='teamid' to='teamid' link-type='inner' intersect='true' >
                                              <link-entity name='systemuser' from='systemuserid' to='systemuserid' link-type='inner' alias='user'>
                                                <attribute name='systemuserid' />
                                             </link-entity>
                                           </link-entity>
                                          </link-entity>  
    <filter type='and'>
                                           <condition attribute='objectid' operator='eq' value='GUID_OF_THE_RECORD' />
                                          </filter>  </link-entity> </entity> </fetch>"; EntityCollection entColAccessTeamMembers = service.RetrieveMultiple(new FetchExpression(strFetchXML)); foreach (Entity record in entColAccessTeamMembers) { RemoveUserFromRecordTeamRequest removeUser = new RemoveUserFromRecordTeamRequest() { Record = new EntityReference(record.LogicalName, record.Id), SystemUserId = (Guid)((AliasedValue)(record["user.systemuserid"])).Value;, TeamTemplateId = teamTemplateGuid }; service.Execute(removeUser); } }

    For more details, see the links below.

    mscrmtechie.blogspot.in/.../retrieve-access-team-members-using.html

    masoodakhtar.wordpress.com/.../addremove-user-tofrom-access-team-in-crm-2013-using-plugin-2/

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans