Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Fetch user id based on email id in ASP.NET

(0) ShareShare
ReportReport
Posted on by

Hello,

I need to fetch the userid associated with email id in ASP.NET. Please suggest.

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Fetch user id based on email id in ASP.NET

    Hi Jagmohan,

    I am implementing in ASP.NET MVC using SDK kindly suggest for the same.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Fetch user id based on email id in ASP.NET

    Hello Bindu,

    You can use following fetch for this


    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
    <entity name="phonecall">
    <attribute name="subject" />
    <attribute name="statecode" />
    <attribute name="prioritycode" />
    <attribute name="scheduledend" />
    <attribute name="createdby" />
    <attribute name="regardingobjectid" />
    <attribute name="activityid" />
    <order attribute="subject" descending="false" />
    <link-entity name="activityparty" from="activityid" to="activityid" link-type="inner" alias="aa">
    <filter type="and">
    <condition attribute="participationtypemask" operator="eq" value="2" />
    <condition attribute="partyid" operator="eq" uiname="Adrian Dumitrascu" uitype="contact" value="{49A0E5B9-88DF-E311-B8E5-6C3BE5A8B200}" />
    </filter>
    </link-entity>
    </entity>
    </fetch>2018_2D00_03_2D00_05_5F00_10_2D00_35_2D00_00.png

  • Community Member Profile Picture
    on at
    RE: Fetch user id based on email id in ASP.NET

    Hi Aric,

    The above snippet was helpful, thank you!

    I need further help on phone call activity for the contact, I have passed the values to  subject and description as mentioned above. How do I pass the parties id as from- to i.e. userid-contact id.

    Please request you to suggest.

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,188 Moderator on at
    RE: Fetch user id based on email id in ASP.NET

    See the functions below to get the user id based on email address:

           public Guid RetrieveUserIdByEmailAddress(string emailAddress)

           {

               QueryByAttribute query = new QueryByAttribute();

               query.ColumnSet = new ColumnSet(new string[] { "systemuserid", "fullname" });

               query.EntityName = "systemuser";

               query.Attributes.Add("internalemailaddress");

               query.Values.Add(emailAddress);

               RetrieveMultipleRequest request = new RetrieveMultipleRequest();

               request.Query = query;

               RetrieveMultipleResponse response = (RetrieveMultipleResponse)service.Execute(request);

               Entity results = (Entity)response.EntityCollection.Entities[0];

               try

               {

                   Guid lookupId = results.Id;

                   return lookupId;

               }

               catch (FaultException<OrganizationServiceFault> ex)

               {

                   throw new InvalidPluginExecutionException(ex.Message);

               }

           }

    If you don't have the contact id, you can follow simiar logic as above function, but query contact entity instead of systemuser entity and add the emailaddress1 attribute instead of internalemailaddress.

    Hope this helps.

  • Community Member Profile Picture
    on at
    RE: Fetch user id based on email id in ASP.NET

    Hello Aric,

    We have integrated CTI to Dynamics 365 so I will have only email id of that agent. Using that email id I need to fetch the user id to create a phone call activity.

    Entity phoneCallEntity = new Entity("phonecall");

               phoneCallEntity["subject"] = "Test Subject";

               phoneCallEntity["description"] ="Test Description";

    Guid activityId = resultService.Create(phoneCallEntity);

    To create phone call activity for the contact I need to pass from(agent user id i.e party id) and to(i.e. particular contact by contact id) which I am not sure with the correct syntax for the same.

    Here I have used Organization Service, so please suggest to complete the above procedure.

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,188 Moderator on at
    RE: Fetch user id based on email id in ASP.NET

    Hi Bindu,

    If I am getting you correct, then you want the user Id of the user in the from field of the email message.

    You can simply call it by using the retrieve function of the OrganizationService.

    Entity email = service.Retrieve("email", emailId, new ColumnSet("from", "subject", "description"));

    Entity from = (Entity)((EntityCollection)(email.Attributes["from"])).Entities[0];

    EntityReference fromPartyId = (EntityReference)from.Attributes["partyid"];

    fromPartyId will contain user id from the email message.

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Fetch user id based on email id in ASP.NET

    Hi Bindu ,

    Try to write Web api query or fetch xml as Wei suggested earlier.

    Webar API URI +

    SystemUser$select=AccessMode,FirstName,FullName,LastName&$filter=IsDisabled eq false and AccessMode/Value ne 5 and AccessMode/Value ne 3 and Email eq "xxxx"

    Here is the reference how to write.

    docs.microsoft.com/.../query-data-web-api

    Hopen this helps.

  • Suggested answer
    karaogluilker Profile Picture
    70 on at
    RE: Fetch user id based on email id in ASP.NET

    Hello Bindu,

    You mean , you want to get the created or updated user in plugin? Or owner off the email?

    If so , i can paste the sample code.  

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Fetch user id based on email id in ASP.NET

    Hi,

    depends on your will, use web api or sdk method to retrieve the user id.

    webapi

    msdn.microsoft.com/.../mt742424.aspx

    SDK

    msdn.microsoft.com/.../gg328117.aspx

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans