Skip to main content

Notifications

Customer Service forum
Unanswered

C# - Extracting value of Activity Party List

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
    Community Member Microsoft Employee on at
    RE: C# - Extracting value of Activity Party List

    Hi Partner,

    Glad your problem was solved!

    And can you share your solution if possible?

    Thanks in advance!

  • D365 Geek Profile Picture
    D365 Geek 32 on at
    RE: C# - Extracting value of Activity Party List

    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
    Community Member Microsoft Employee on at
    RE: C# - Extracting value of Activity Party List

    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.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,818 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,147 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans