web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,983 Moderator on at
    RE: PhoneCall Activity C#

    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
    RE: PhoneCall Activity C#

    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,983 Moderator on at
    RE: PhoneCall Activity C#

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 149

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 132

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 123 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans