I need to make a plugin that is triggered whenever a task is updated. Which of the attributes in the post image will give me the emailId of the person to whom the task is assigned.
*This post is locked for comments
I need to make a plugin that is triggered whenever a task is updated. Which of the attributes in the post image will give me the emailId of the person to whom the task is assigned.
*This post is locked for comments
ps- it won't be in the post image as that will stop at the owninguserid and not carry related entity values
string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='task'>
<attribute name='activityid' />
<filter type='and'>
<condition attribute='activityid' operator='eq' uitype='task' value='" + activityid.ToString()here + @"' />
</filter>
<link-entity name='systemuser' from='systemuserid' to='owninguser' visible='false' link-type='outer' alias='assignee'>
<attribute name='internalemailaddress'/>
</link-entity>
</entity>
</fetch>";
Entity yllennod = service.RetrieveMultiple(new FetchExpression(fetchXML));
search the syntax for how to pull the (AliasedValue)assignee.internalemailaddress from yllennod.Entities[0].
This is a complicated question, and you might get a better result on the forums if you could provide some of your source.
You can get a plugin to act when an entity is updated (task is updated). I guess there is logic in the plugin or a workflow to set task assignment, you can grab this in your plugin and look up systemuser. The email should be there.
Hi,
If you plugin is triggering on task update then you can only get fields from the task entity. You need to get the owner of the task (ownerid) and then retrieve the details separately using retrieve.
Something like this-
=======================
public class SamplePlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
tracingService.Trace("Plugin enetering in update");
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
// Obtain the organization service reference.
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);
// Obtain the target entity from the post image
var entity = (Entity)context.PostEntityImages["postImage"];
if (entity.Contains("ownerid"))
{
var owner = entity.GetAttributeValue<EntityReference>("ownerid");
if (owner.LogicalName == "systemuser")
{
var ownerDetails = service.Retrieve(owner.LogicalName, owner.Id, new ColumnSet(true));
var ownerEmail = ownerDetails.GetAttributeValue<string>("internalemailaddress");
}
}
}
}
}
===============================
Hope this helps.
André Arnaud de Cal... 291,711 Super User 2024 Season 2
Martin Dráb 230,458 Most Valuable Professional
nmaenpaa 101,156