Here comes the interesting issue. I want to know any settings makes this difference or any workaround to get it right.
We have different Dynamics 365 CRM online instances but all are identical as they are refreshed from Prod. Recently developed plugin code behaves differently across the environments.
var organizers = (EntityCollection)appointment["organizer"];
Entity record = organizers.Entities[0];
EntityReference organizer = (EntityReference)record["partyid"];
On appointment creation, the post-create async plugin code read the organizer
- one of the activity party field but the result is very different. Though systemuserid
is identical, the name is coming from that entity reference properly in Dev but coming as null
in other environments.
MS agreed this as a bug, but actually this context difference is identified between the classic web UI & the UCI. Only for appointment entity, because of some oData response known issue - UCI target entity is missing the formatted values.
I got the plugin profiler log from my QA team so I didn't realize they were testing in UCI but I tested in web, so the quick watch showed the difference while replay/debugging.
Anyway until MS prioritize & fix this bug, I have the below workaround to unblock this issue.
#region Workaround for fixing UCI app EntityReference coming as empty string
if (string.IsNullOrEmpty(organizer.Name))
{
ctLog.Log("organizer.Name is empty");
fetch = string.Format(@"<fetch>
<entity name='systemuser' >
<attribute name='fullname' />
<filter type='and' >
<condition attribute='systemuserid' operator='eq' value='{0}' />
</filter>
</entity>
</fetch>", organizer.Id);
ctLog.Log("fetch built");
results = userOrgService.RetrieveMultiple(new FetchExpression(fetch));
ctLog.Log("results count: " + results.Entities.Count);
if (results.Entities.Count > 0)
{
organizer.Name = results.Entities[0].GetAttributeValue<string>("fullname");
}
}
#endregion