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.