Skip to main content

Notifications

Announcements

No record found.

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.

  • Verified answer
    Bipin D365 Profile Picture
    28,961 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

  • 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

  • Suggested answer
    Bipin D365 Profile Picture
    28,961 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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,274 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,947 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans