Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to get the email of the person to whom the task is assigned ?

(0) ShareShare
ReportReport
Posted on by

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

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,010 on at
    RE: How to get the email of the person to whom the task is assigned ?

    ps- it won't be in the post image as that will stop at the owninguserid and not carry related entity values

  • Suggested answer
    Martin Donnelly Profile Picture
    Martin Donnelly 1,010 on at
    RE: How to get the email of the person to whom the task is assigned ?

    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].

  • Suggested answer
    _Lars_ Profile Picture
    _Lars_ 225 on at
    RE: How to get the email of the person to whom the task is assigned ?

    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.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to get the email of the person to whom the task is assigned ?

    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.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans