web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

populate form onLoad

(0) ShareShare
ReportReport
Posted on by 95

Hello All,

I want to populate a form onLoad so that the number of contacts linked to an account is displayed. I am unsure how to do this.
I am a novice to using CRM, and am unsure whether to use a workflow, JavaScript, or some other method I'm unfamiliar with.

I wish to do the actual work myself, but any help/advice on what to use/do to make this work would help a lot.
I've already scoured the internet for help, but people are decidedly unhelpful.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    ScottDurow Profile Picture
    21 on at

    Hi,

    The first thing to decide is where you want to display the number of contacts:

    1. You can display as a Web Resource that is embeded in the form - this will be display only

    2. You could create a dummy field on the form which will be populated dynamically. This could then be used in advanced find however you would need to create plugin to keep it up to date when ever a new contact is added or removed.

    To get the count of contacts, you will need to execute a fetchxml query - this can easily be done in Javascript using xrmsvctoolkit.codeplex.com or xrmservicetoolkit.codeplex.com

    You could have some code that might look like:

    function fetchOperationCountSync()

    {

       var count;

       var fetchXml =

    "<fetch distinct='true' mapping='logical' aggregate='true'>" +

    "    <entity name='contact'> " +

    "       <attribute name='contactid' alias='contact_count' aggregate='countcolumn' /> " +

    "      <filter type='and'>" +

    "        <condition attribute='parentcustomerid' operator='eq' value='" + Xrm.Page.data.entity.getId() + "' />" +

    "      </filter>" +

    "    </entity> " +

    "</fetch>";

       XrmSvcToolkit.fetch({

           fetchXml: fetchXml,

           async: false,

           successCallback: function (result)

           {

               count = result.entities[0]["contact_count"];

           },

           errorCallback: function (error)

           {

               throw error;

           }

       });

       return count;

    }

    hth,

    Scott

  • Suggested answer
    Matthew Olds Profile Picture
    95 on at

    Thank you for the swift reply. You would not believe how many other places I had asked for help, and received none.

  • Matthew Olds Profile Picture
    95 on at

    Could you elaborate on the xrmsvctoolkit ? I'm unsure what it is/what to do with it.

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi,

    It is a managed solution that you'll need to import into your Dynamics CRM Organization. Once imported, you can then included it on forms and use the library. Read more on Javascript Web resources here - msdn.microsoft.com/.../hh771584.aspx

    hth

  • Matthew Olds Profile Picture
    95 on at

    Again, many thanks for the swift reply. This has been the most productive interaction I've had all month.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans