Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Search Account from a Contact in Entity "Phonecall"

(0) ShareShare
ReportReport
Posted on by

Hi all,

i have the following problem. 

In the entity "phonecall" we have the partylist "from". If this feeld is filled with a contact record i want to find the suitable account to this contact and save it in a new lookup feeld. 

From the partylist i can get following informations: 

  1. activityPartyId:"{F6DD7A31-91E5-E711-812A-70106FA68211}"
  2. ambiguousRecordsXml:undefined
  3. category:undefined
  4. data:undefined
  5. displayClass:undefined
  6. entityType:"contact"
  7. id:"{45DF2A58-FA9D-E711-810F-70106FAA9741}"
  8. isProcessEnabled:"True"
  9. name:"Andrea Augustin"
  10. onclick:undefined
  11. processId:undefined
  12. processTimestamp:undefined
  13. selected:undefined
  14. type:"2"
  15. typename:undefined

Is it possible to find the account from a contact only with the contact id? And how can i achieve my goal? 

Please help me =)

 


*This post is locked for comments

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Search Account from a Contact in Entity "Phonecall"

    Hi,

    Once you get the contact id, you need to fetch the account from that contact. For this you can use WEB API.

    Below is the sample code. You need to update the field schema name as per your organization

    =============

    function onChangeFrom() {

       var party = Xrm.Page.getAttribute("from");

       var members = party.getValue();

       if (members != null) {

           for (var i = 0; i < members.length; i++) {

               if (members[i].type == 2) {              

                   var req = new XMLHttpRequest();

                   req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts(" + members[i].id.replace("{", "").replace("}", "") + ")?$select=_parentcustomerid_value", true);

                   req.setRequestHeader("OData-MaxVersion", "4.0");

                   req.setRequestHeader("OData-Version", "4.0");

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

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

                   req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

                   req.onreadystatechange = function () {

                       if (this.readyState === 4) {

                           req.onreadystatechange = null;

                           if (this.status === 200) {

                               var result = JSON.parse(this.response);

                               var _parentcustomerid_value = result["_parentcustomerid_value"];

                               var _parentcustomerid_value_formatted = result["_parentcustomerid_value@OData.Community.Display.V1.FormattedValue"];

                               var _parentcustomerid_value_lookuplogicalname = result["_parentcustomerid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

                               // Create lookup object

                               var accountLookup = new Array();

                               accountLookup[0] = new Object();

                               accountLookup[0].id = _parentcustomerid_value;

                               accountLookup[0].name = _parentcustomerid_value_formatted;

                               accountLookup[0].entityType = _parentcustomerid_value_lookuplogicalname;

                               Xrm.Page.getAttribute("new_fromaccount").setValue(accountLookup);

                           } else {

                               Xrm.Utility.alertDialog(this.statusText);

                           }

                       }

                   };

                   req.send();

               }

           }

       }

    }

    ================================

    Hope this helps.

  • Michel Gueli Profile Picture
    Michel Gueli 982 on at
    RE: Search Account from a Contact in Entity "Phonecall"

    If you do this client side, it only works when you open the form. I don't know what the requirements are.

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: Search Account from a Contact in Entity "Phonecall"

    you definitely can do that with javascript & just need some WebApi action

    for e.g

    GET [Organization URI]/api/data/v8.2/accounts?$select=name&$filter=contains(name,'sample')&$count=true HTTP/1.1

    you would anyway have the name of the contact or guid. just retrieve the account using that guid of the contact.

    if you want to study more on how to query data with Web API , please see below link :

    www.inogic.com/.../querying-data-in-microsoft-dynamics-crm-2016-using-web-api

    kindly mark this answer as verified if helpful.

  • Michel Gueli Profile Picture
    Michel Gueli 982 on at
    RE: Search Account from a Contact in Entity "Phonecall"

    Is this server side? If you have the id of the contact, you can retrieve the contact record.

    var contact = service.Retrieve("contact", contactId, new ColumnSet("parentcustomerid"));

    if(contact.Contains("parentcustomerid"))

    {

       var accountName = contact.GetAttributeValue<EntityReference>("parentcustomerid").name;

    }

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans