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)

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

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