web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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.

  • Zucko_mac Profile Picture
    195 on at

    thanks you works perfectly

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans