Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

(0) ShareShare
ReportReport
Posted on by 15

I am working on a project require to count the number of related records of child entity and display the number of related records on parent form.

 any ideas how may I can do this.

*This post is locked for comments

  • Arulmozhi N Profile Picture
    Arulmozhi N 40 on at
    RE: how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

    Hi Mohamed,

          I have a solution for your question.

    Step 1: Create a webresource for a parent entity.

    Step 2: write the below code in onload function on webresource

    updatenumber of related records: function(executionContext) {
     var requestId=Xrm.Page.data.entity.getId().replace("{","").replace("}","");
    var fetchXml = "<fetch xmlns:generator='MarkMpn.SQL4CDS' aggregate='true'><entity name='child entity name'><attribute name='child entityid' alias='NoOfcountSection' aggregate='count' /><filter><condition attribute='parent entity name' operator='eq' value='" + requestId + "'/></filter></entity></fetch>"
    fetchxml="?fetchXml="+encodeURIComponent(fetchXml);
    Xrm.WebApi.online.retrieveMultipleRecords("child entity name", fetchxml).then(
    function success(results) {
                    for (i=0;i<results.entities.length;i++){
                   var result = results.entities[i];
                  var record = {};
    record.cpn_number of related records = result["NoOfcountSection"].toString(); // Text
    Xrm.WebApi.online.updateRecord("cpn_request", requestId, record) then(
        function success(result) {
            var updatedId = result.id.
            console.log(updatedId).
    },
        function(error) {
            console.log(error.message);
        }
    );
    location.reload();
    }
    },
        function(error) {
            console.log(error.message);
        }
    );
    }
    };

    Step 3: In form properties add the above method name in onload.

  • Accenture Profile Picture
    Accenture 5 on at
    RE: how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

    Can you please tell me the code for this?

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

    Guys he need that functionality in CRM 2011, Rollup field is not available in CRM 2011 :)

  • ehsan af Profile Picture
    ehsan af 215 on at
    RE: how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

    سلام

  • ehsan af Profile Picture
    ehsan af 215 on at
    RE: how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

    you can create rollup field that count related entity you want .

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

    Hi Mohamed

    You could add a new whole number field to the parent entity, and set field type to rollup. Then, choose the related entity you wish to count, apply any filters (e.g. status = active) and set aggregation to count of the child entity. You can do this without code.

    Regards

    James.

  • Moh Helper Profile Picture
    Moh Helper 250 on at
    RE: how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

    Hi Saeid,

    Here two articles allowing to understand how create a plugin and how you can registered in CRM:

    www.tutorialspoint.com/.../microsoft_crm_plugins.htm

    www.tutorialspoint.com/.../microsoft_crm_plugin_registration.htm

    Kind regards,

    Moh

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

    In that case you can also use workflow instead of going through coding path, Please look into this thread you will see multiple option for the same (including workflow one) : community.dynamics.com/.../147466

    This should surely help you, let me know if you still need any help.

    Thanks

  • Mohamed Saeid Profile Picture
    Mohamed Saeid 15 on at
    RE: how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

    it would be nice if you shared article talking about this subject, I am new to coding.

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: how I can count number of records of child related entity and display the total number of related records on parent entity form - MS Dynamics 2011

    Hi,

    You can use JS code or plugin on create/update/delete of child record to update parent record with the numbers.

    Thanks

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans