Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Issue Add user in Team Template C# code

Posted on by 195

I have the following business logic:

When you add a record the fields required attendees and optional attendees, must check that these records are system user type, then insert them in an access team template, this in the entity appoitment. This is my code; however, when executing it I get the following error: Privilege Type Share not defined on entity 'SystemUser'

private static void regardinCitas()
{


Entity cita = _service.Retrieve("appointment", new Guid("A9E39164-4980-E811-942F-00505681106C"), new ColumnSet(true));

if (cita.Attributes.Contains("requiredattendees") || cita.Attributes.Contains("optionalattendees"))
{

EntityCollection requeridos = cita.GetAttributeValue<EntityCollection>("requiredattendees");
EntityCollection opcionales = cita.GetAttributeValue<EntityCollection>("optionalattendees");

EntityCollection usuariosParticipantes = new EntityCollection();

foreach (Entity partR in requeridos.Entities)
{
if (partR.GetAttributeValue<EntityReference>("partyid").LogicalName == "systemuser")
{
usuariosParticipantes.Entities.Add(partR);
}
}

foreach (Entity partO in opcionales.Entities)
{
if (partO.GetAttributeValue<EntityReference>("partyid").LogicalName == "systemuser")
{
usuariosParticipantes.Entities.Add(partO);
}
}


foreach(Entity usuario in usuariosParticipantes.Entities)
{
AddUserToRecordTeamRequest teamAddRequest = new AddUserToRecordTeamRequest();
teamAddRequest.Record = new EntityReference("systemuser",usuario.GetAttributeValue<EntityReference>("partyid").Id);
teamAddRequest.SystemUserId = usuario.GetAttributeValue<EntityReference>("partyid").Id;
teamAddRequest.TeamTemplateId = new Guid("2A25FF10-F0F2-E811-9437-00505681106C");
_service.Execute(teamAddRequest);
}

*This post is locked for comments

  • Zucko_mac Profile Picture
    Zucko_mac 195 on at
    RE: Issue Add user in Team Template C# code

    thanks you works perfectly

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Issue Add user in Team Template C# code

    Hello,

    You have issues on line here:

    teamAddRequest.Record = new EntityReference("systemuser",usuario.GetAttributeValue<EntityReference>("partyid").Id);

    Instead of putting reference of user there you should put reference of entity you want to enable TeamAccess like opportunity or so.

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans