Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Issue Add user in Team Template C# code

(0) ShareShare
ReportReport
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
    195 on at
    RE: Issue Add user in Team Template C# code

    thanks you works perfectly

  • Verified answer
    a33ik Profile Picture
    84,331 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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans