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 :
Service | Customer Service, Contact Center, Fie...
Unanswered

C# - Extracting value of Activity Party List

(0) ShareShare
ReportReport
Posted on by 32

HI,

I am working on a plugin that should fetch the value of the To field in a custom entity of type Activity and populate it in the ownerid field of the same Activity custom entity.  

Here is my code:

 string chatActivityFetch = @"
                 <fetch distinct = 'false' mapping='logical'  output-format='xml-platform' version='1.0'>
                  <entity name='cxlvhlp_chatactivity'>
                  <attribute name='activityid'/>
                  <attribute name='subject' />
                  <attribute name='createdon'/>
                  <attribute name='to'/>
                  <attribute name='cxlvhlp_skill'/>
                  <attribute name='ownerid'/>
                  <order attribute='subject' descending='false'/>
                  <filter type='and'>
                  <condition attribute='owneridname' operator='like' value='%Power Platform CoE%'/>
                  <filter type='or'>
                  <condition attribute='cxlvhlp_skill' operator='like' value='%fcaccount%'/>
                  <condition attribute='cxlvhlp_skill' operator='like' value='%Unassigned%'/>
                </filter>
               </filter>
               </entity>
              </fetch>";
 EntityCollection result = service.RetrieveMultiple(new FetchExpression(chatActivityFetch));
                if (result != null && result.Entities.Count > 0)
                {
                   
                    foreach (Entity chatRec in result.Entities)
                    {
                   Guid chatId = new Guid();
                    chatId = chatRec.Id;
                  string ToFieldName = ChatActivityToFieldValue(service, tracingService, wfcontext, chatRec, chatId .Id);
                  if (ToFieldName != null)
                        {
chatRec["ownerid"] = new EntityReference("systemuser", ToChatRecordValue);
 service.Update(chatRec);
}
 private string ChatActivityToFieldValue(IOrganizationService service, ITracingService tracingService, IWorkflowContext wfcontext, Entity chatRec, Guid Id)
        {
 var qe2 = new QueryExpression() { EntityName = "systemuser" };
            tracingService.Trace("This is step 5");
            qe2.ColumnSet = new ColumnSet("domainname", "fullname", "systemuserid");
            var filter1 = new FilterExpression();
            tracingService.Trace("This is step 8");
            filter1.AddCondition(new ConditionExpression("systemuserid", ConditionOperator.Equal, Id));
            tracingService.Trace("This is step 11");
            qe2.Criteria.AddFilter(filter1);
            tracingService.Trace("This is step 10");
            EntityCollection ec = service.RetrieveMultiple(qe2);
            tracingService.Trace("This is step 6");
            if (ec.Entities.Count > 0)
            {
                foreach (var chatrecord in ec.Entities)
                {
                    tracingService.Trace("Attempt to set the value of ToChatRecordValue.");
                    tracingService.Trace("Step 13 - The system user guid is " + " " + chatrecord["systemuserid"].ToString());
                   
                    ToChatRecordValue = (Guid)chatrecord["systemuserid"];
                }
               
            }
            return ToChatRecordValue.ToString();
        }
        }
    }
The above FetchXML gets all relevant record to be edited, but the mapping is not accurate.  I think the QueryExpression may not be correct.
Precisely, I would like to know how to obtain the value of the To field in an entity of type Activity using C#.  Thank you in advance.
  • Community Member Profile Picture
    on at

    Hi Geek,

    Maybe you can refer following link, which using form field to populate regarding field:

    How to Retrieve and Set partylist value form email activity using plugin (microsoft.com)

    From the code you post above, you have get activity record id.

    foreach (Entity chatRec in result.Entities)
                        {
                       Guid chatId = new Guid();
                        chatId = chatRec.Id;
                       ...
    } 
    Maybe you can use Entity.GetAttributeValue<T> to get to field value.

  • D365 Geek Profile Picture
    32 on at

    Thanks for your input. I tried it but did not get the right result.  The problem however was resolved using Flow.  

    Thank you.

  • Community Member Profile Picture
    on at

    Hi Partner,

    Glad your problem was solved!

    And can you share your solution if possible?

    Thanks in advance!

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 Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
11manish Profile Picture

11manish 48 Super User 2026 Season 2

#2
Travis South Profile Picture

Travis South 45

#3
Ayesha Wajahat Profile Picture

Ayesha Wajahat 18

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans