web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get user email from plugin ?

(0) ShareShare
ReportReport
Posted on by

I have made a plugin that works whenever a task is created in CRM. I need to get the email address of the person who has created the task but I am unable to do so. I have also created a post Image but with that I'm only able to get the userid form the person who created. Can someone please help with this

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    T.I.A Profile Picture
    1,760 on at

    Entity user = service.Retrieve("systemuser", userId, new ColumnSet(new String[] { "internalemailaddress" }));

    This will get the primary email address of the user.

  • vagargg Profile Picture
    on at
    [deleted]
  • T.I.A Profile Picture
    1,760 on at

    Correct

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at

    You have to retrieve email id from systemuser entity with help of ownerid of task.

  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    2,545 on at

    Hi,

    You will have to fetch user details from systemuser table by passing userid. In Create plugin, there is no need to get postimage as you will automatically get the ownerid of the record in context (which is userid). You can use service.retrieve method on systemuser table to get the email address of the user. 
     
    Entity objUser = service.Retrieve("systemuserid", userGuid, new ColumnSet("primaryemailaddress","systemuserid"));
    if (objUser != null && objUser.Contains("primaryemailaddress") && objUser["primaryemailaddress"] != null)
                {
                    string Useremail = (string)objUser["primaryemailaddress"];
                }
  • vagargg Profile Picture
    on at

    Do you need to install some other dependencies for this to work. I can't find a function named service

  • T.I.A Profile Picture
    1,760 on at

    public class Example : IPlugin

    {

    public void Execute(IServiceProvider serviceProvider)

    {

    IPluginExecutionContext pluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    IOrganizationService service = factory.CreateOrganizationService(pluginExecutionContext.UserId);

    Entity task = pluginExecutionContext.InputParameters["Target"] as Entity;

    etc.

  • Verified answer
    T.I.A Profile Picture
    1,760 on at

    public class Example : IPlugin

    {

    public void Execute(IServiceProvider serviceProvider)

    {

    IPluginExecutionContext pluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    IOrganizationService service = factory.CreateOrganizationService(pluginExecutionContext.UserId);

    Entity task = pluginExecutionContext.InputParameters["Target"] as Entity;

    Guid userId = pluginExecutionContext.UserId;

    Entity user = service.Retrieve("systemuser", userId, new ColumnSet(new String[] { "internalemailaddress" }));

    be sure do to null checking

  • Himanshuram Ranjan Profile Picture
    5 on at

    Entity objUser = Proxy.Retrieve("systemuser", userId, new ColumnSet("internalemailaddress", "systemuserid"));

                           if (objUser != null && objUser.Contains("internalemailaddress") && objUser["internalemailaddress"] != null)

                           {

                               string Useremail = (string)objUser["internalemailaddress"];

                               Console.WriteLine(Useremail);

                           }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans