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 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 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.
Can you please tell me the code for this?
Guys he need that functionality in CRM 2011, Rollup field is not available in CRM 2011 :)
سلام
you can create rollup field that count related entity you want .
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.
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
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
it would be nice if you shared article talking about this subject, I am new to coding.
Hi,
You can use JS code or plugin on create/update/delete of child record to update parent record with the numbers.
Thanks
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156