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)

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

I have the same question (0)
  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    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

  • Suggested answer
    karaogluilker Profile Picture
    70 on at

    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
    gdas Profile Picture
    50,091 Moderator on at

    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
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

  • Community Member Profile Picture
    on at

    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.

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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

    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.

  • Suggested answer
    Community Member Profile Picture
    on at

    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

    Hi Jagmohan,

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

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