Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Populating To field in Email activity

Posted on by 45

I have created a custom entity for a specific type of contact.

The entity has been enabled for email and I have added the social pane to the form.

However when I click the New Email under the ellipsis the To field is not populated with the email address.

I have to search for it under the Lookup Records dialog pop up.

Can someone help me set the default To from the record that has opened the email activity for this custom entity please.

Thank you.

*This post is locked for comments

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: Populating To field in Email activity

    you can do it using a simple below code ;you will have to get the contact fields from regarding and set it on to field :

    SetPartyList: function (contactId, customerName, cEmail) {

           var partyRequired = Xrm.Page.getAttribute("to");

           // Create new array

           var partlist = new Array();

           partlist[0] = new Object();

           partlist[0].id = contactId; //Guid (i.e., Guid of User or Contact etc)

           partlist[0].name = customerName; //Name (i.e., Name of User or Contact etc)

           //partlist[0].EMailAddress1 = cEmail;

           partlist[0].entityType = "contact"; //entity schema name of account or contact

           // Set array value

           partyRequired.setValue(partlist);

       },

    getContactEmail: function () {

           // Call this function from CRM Form Attribute OnChange  

           //RSA.Email.getContactEmail

           try {

               if (Xrm.Page.getAttribute("to").getValue() != null)

                   return;

               //var accountId = window.top.opener.top.opener.Xrm.Page.data.entity.getId();

               var id = Xrm.Page.getAttribute("regardingobjectid").getValue()[0].id;

               var contactId = id.slice(1, -1);

               var serverUrl;

               if (Xrm.Page.context.getClientUrl !== undefined) {

                   serverUrl = Xrm.Page.context.getClientUrl();

               }

               else {

                   serverUrl = Xrm.Page.context.getServerUrl();

               }

               var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

               var contactRequest = new XMLHttpRequest();

               contactRequest.open("GET", ODataPath + "/ContactSet(guid'" + contactId + "')", false);

               contactRequest.setRequestHeader("Accept", "application/json");

               contactRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");

               contactRequest.send();

               //If request was successful, parse the email address

               if (contactRequest.status == 200) {

                   var retrievedContact = JSON.parse(contactRequest.responseText).d;

                   var cEmail = retrievedContact.EMailAddress1;

                   var cName = retrievedContact.FullName;

                  SetPartyList(contactId, cName, cEmail);

                   //cEmail != null ? Xrm.Page.getAttribute('to').setValue(cEmail) : '';

               }

               else {

                   console.log('request failed.');

               }

               Xrm.Page.getAttribute('to').setSubmitMode("always");

           }

    you can take a reference from it and use web api in between to retrieve the values from contact.

    mark my answer as verified if helpful

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans