Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Bind all the contacts in text box which account name we enter

(0) ShareShare
ReportReport
Posted on by

I create a new form in Account entity , here we add a button in ribbon that name Getting Contacts, I add two fields one is Account Name and another one is Associated Contacts.


When I enter a Account Name,and click on Getting Contacts Button, then all the related Contacts of of this account is bind In Associate Contacts Multi-textbox.
How to do this?

Please give me a suggestion.

*This post is locked for comments

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at
    RE: Bind all the contacts in text box which account name we enter

    Try below code:

    function retrieveContactsOfAccount()

    {

    var accountId = Xrm.Page.getAttribute('<account lookup schema name>').getValue();
    var contactList = Xrm.Page.getAttribute('<mutiline text field schema name>').getValue();
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/contacts?$select=firstname,lastname,fullname&$filter=_accountid_value eq " + accountId + "", false);
    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=\"OData.Community.Display.V1.FormattedValue\"");
    req.setRequestHeader("Prefer", "odata.maxpagesize=10");
    req.onreadystatechange = function () {
    if (this.readyState === 4) {
    req.onreadystatechange = null;
    if (this.status === 200)
    {
    var results = JSON.parse(this.response);
    for (var i = 0; i < results.value.length; i++)
    {

    var fullname = results.value[i]["fullname"];

    contactList+= fullname+"\n";

    }
    Xrm.Page.getAttribute("<mutiline text field schema name>").setValue(contactList);
    }
    else
    {
    alert(this.statusText);
    }
    }
    };
    req.send();
    }


    If found useful, please mark the answer as verified.


    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.com

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Bind all the contacts in text box which account name we enter

    Hi,

    can't you achieve your requirement with a subgrid pointing to the associated contacts?

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at
    RE: Bind all the contacts in text box which account name we enter

    Hello,

    You would like to copy the associated contacts that are listed in the Child Contacts subgrid and store the names in a multiple line of text field ?  

    Would it help if you add the Subgrid on the new form ?

    If you want to move ahead with the Multiline Textbox you can do following (depending on which CRM you are using)  

    If you are using CRM 2016 or later (Dynamics 365), you can create a request using the WebApi and retrieve all the child contacts associated with the account.

    To the request, you can pass in a FetchXml (you can get that from an Advanced Find - Download FetchXml) - where you add the AccountId of the respective account as a parameter.

    To get the account id, you can use following command: Xrm.Page.data.entity.getId() - see [View:https://msdn.microsoft.com/en-us/library/gg334720.aspx#BKMK_getId:750:50]

    To send a retrieve request to the WebAPI with a FetchXml parameter please see: [View:https://msdn.microsoft.com/en-us/library/mt607533.aspx#bkmk_useFetchXML:750:50] -> you will need to URL encode it before sending the request

    Once you get the results, you can iterate through the collection and append the names to the Multiple Line of Text field using Xrm.Page.getAttribute("prefix_yourfield").setValue("list_of_contacts").

    Hope this helps,

    Radu   

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
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans