Announcements
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
Hi,
You can use JS code or plugin on create/update/delete of child record to update parent record with the numbers.
Thanks
it would be nice if you shared article talking about this subject, I am new to coding.
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.
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
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.
you can create rollup field that count related entity you want .
سلام
Guys he need that functionality in CRM 2011, Rollup field is not available in CRM 2011 :)
Can you please tell me the code for this?
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.
Jump in, show your community spirit, and win prizes!
Expanding mentorship, skilling, and AI innovation
These are the community rock stars!
Stay up to date on forum activity by subscribing.
ScottDurow 2
GJones 1