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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

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

    Thanks

  • Mohamed Saeid Profile Picture
    15 on at

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

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    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

  • Moh Helper Profile Picture
    250 on at

    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
    Community Member Profile Picture
    on at

    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.

  • ehsan af Profile Picture
    215 on at

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

  • ehsan af Profile Picture
    215 on at

    سلام

  • Mahendar Pal Profile Picture
    45,095 on at

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

  • Accenture Profile Picture
    5 on at

    Can you please tell me the code for this?

  • Arulmozhi N Profile Picture
    40 on at

    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.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans