Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

how to implement access team

Posted on by 255

I have created Access team template for account entity and added a sub grid on Account entity that is used to assign users.
When any user is added in the grid , then it should also add its Manager in the grid . 
For this, i have created a plugin to implement it, but the code is not able to fetch the manager field into the sub grid.

public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


EntityReference id = null;
EntityReference targetEntity = null;
EntityReference relatedEntity = null;
string relationshipName = string.Empty;
EntityReferenceCollection relatedEntities = null;


if (context.MessageName == "Associate")
{
if (context.InputParameters.Contains("Relationship"))
{
relationshipName = context.InputParameters["Relationship"].ToString();
}

if (relationshipName != "user_accounts")
{
return;
}
else
{
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
{
targetEntity = (EntityReference)context.InputParameters["Target"];
tracingService.Trace("Target Entity " + targetEntity.LogicalName.ToString() + targetEntity.Id.ToString());
}


if (context.InputParameters.Contains("RelatedEntities") && context.InputParameters["RelatedEntities"] is EntityReferenceCollection)
{
relatedEntities = context.InputParameters["RelatedEntities"] as EntityReferenceCollection;
relatedEntity = relatedEntities[0];
tracingService.Trace("Related Entity Ref " + relatedEntity.LogicalName.ToString() + relatedEntity.Id.ToString());
}


Entity RetrieveUser = service.Retrieve("systemuser", targetEntity.Id, new ColumnSet("parentsystemuserid"));

if (RetrieveUser.Attributes.Contains("parentsystemuserid") && RetrieveUser.Attributes["parentsystemuserid"] != null)
{
id = RetrieveUser.GetAttributeValue<EntityReference>("parentsystemuserid");
tracingService.Trace("Parent SystemUser Id " + id.Id.ToString());
AssociateContactsToAccount(relatedEntity, id, service);
}

}

}

}


public static void AssociateContactsToAccount(EntityReference account, EntityReference user, IOrganizationService service)
{

// Creating EntityReferenceCollection for the Contact
EntityReferenceCollection relatedEntities = new EntityReferenceCollection();

// Add the related entity contact
relatedEntities.Add(account);

// Add the Account Contact relationship schema name
Relationship relationship = new Relationship("user_accounts");

// Associate the contact record to Account
service.Associate(user.LogicalName, user.Id, relationship, relatedEntities);

}

*This post is locked for comments

  • Mihir Maruti Kadam Profile Picture
    Mihir Maruti Kadam 700 on at
    RE: how to implement access team

    Hi Alex,

    Your explanation is correct. We can use associate request when more than one user present in the grid.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: how to implement access team

    Pretty sure it will - used it myself just recently on the access teams.. BUT the team has to exist(and it does not exist if there are no users added to the grid). That's the case, though, when adding a manager of the user who is already in the team. You are probably right in that it's better to use recommended approach.

    Still, that relationship name has to be fixed as well.

  • Suggested answer
    Mihir Maruti Kadam Profile Picture
    Mihir Maruti Kadam 700 on at
    RE: how to implement access team

    Hi Anat,

    The Associate request will not work for Access team because its special type of grid. We have to use AddUserToRecordTeamRequest to add user in access team

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: how to implement access team

    Hi Anat,

     you are using a different relationship name there - it should not be user_accounts, it should be teammembership_association (looks like that code was meant to be used for contacts-accounts originally)

     To Mihir's point, you can also use a different request, but, I think, either way should work. That special request just ensures that AccessTeam exists as far as I know (since it can be removed once there are no users in it)

  • Suggested answer
    Mihir Maruti Kadam Profile Picture
    Mihir Maruti Kadam 700 on at
    RE: how to implement access team

    Hi Anat,

    To Add new user in Access team template, there is new request "AddUserToRecordTeamRequest".

    please refer below link

    mscrmtechie.blogspot.in/.../add-user-from-access-team-crm-2013-and.html

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