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)

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

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    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   

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

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

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at

    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

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