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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

PhoneCall Activity C#

(0) ShareShare
ReportReport
Posted on by 5

I guess this question has been asked before, however, I am a programming beginner and started with the part of the code that I will show you later, I appreciate your patience.

I have managed to create a Telephone Activity with the following characteristics: Subject, Description, Address, From, etc ... However, I have not been able to associate the "To" with the logged in user, could you see what I have done and tell me what I am doing wrong , please.


var nombreVariable = (from q in crmContext.ContactSet where q.MobilePhone == "xxxxxxx" select q).FirstOrDefault();
var Usuario = (from q in crmContext.SystemUserSet where q.PersonalEMailAddress == "xxxxxx" select q).FirstOrDefault();

IEnumerable<ActivityParty> party = new[] { new ActivityParty { LogicalName = ActivityParty.EntityLogicalName, PartyId = new EntityReference("contact", nombreVariable.Id), } };

IEnumerable<ActivityParty> party2 = new[] { new ActivityParty { LogicalName = ActivityParty.EntityLogicalName, PartyId = new EntityReference("SystemUserId", Usuario.Id), } };

PhoneCall crearphonecall = new PhoneCall
{
Subject = "Test Phocall # 5", 
Description = "Test PhoeCall",
DirectionCode = false, 
ActualDurationMinutes = xx, 
PhoneNumber = "xxxxxx",
StateCode = PhoneCallState.Open, //Open, Completed, Canceled
//RegardingObjectId = new EntityReference("contact", nombreVariable.Id),
From = party,
To= party2

};
_orgService.Create(crearphonecall);

I appreciate all the help you can give me.

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    Use below code to set activity party field such as TO field.

    // Create a new activity party linked to a contact

    Entity party1 = new Entity("activityparty");

    party1["partyid"] = new EntityReference("contact", contactId);

    // Create a new EntityCollection and add the 2 parties

    EntityCollection to = new EntityCollection();

    to.Entities.Add(party1);

    check below blog link to learn more.

    blog.magnetismsolutions.com/.../working-with-dynamics-crm-activity-party-lists-in-c--plugins

    Please mark my answer verified if i were helpful

  • JuanJ Espinoza Profile Picture
    5 on at

    Please advise me if I'm wrong. This example shows me how to complete the "TO" field with the information of an existing contact/lead in my CRM, however I need complete it with the system user who logged into the CRM.

    Example, The client/lead Pedro, calls the agent Juan. In that case, the "FROM" is Pedro, and the "TO" is Juan, with Juan being a user of the system and not a Lead or a client.

    pastedimage1606105061939v1.png

    I appreciate your comments

  • Verified answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    HI,

    You can use same to code to set TO with logged in user. You will need to replace contact with systemuser and contactId with logged in user ID.

    I have given reference on how to set activity party field which can be used to set any other entity apart from what I shown in my example which is COntact entity.

    Please mark my answer verified if i were helpful

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 151 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 134

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 55 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans