Dynamic CRM 2013 Learning Notes (11) using JavaScript to implement child table totals (summary, sum) functions

Source: Internet
Author: User

We often have a requirement that, after adding or modifying a value in a sub-table, it is necessary to display its and displayed on the main sheet immediately in the main list. If implemented with a plug-in, you can achieve the sum, but the page will have to refresh to display correctly. At this point, consider the use of JS to achieve this function, and automatically refresh the page, so that the sum of the value immediately displayed on the main table.

New or modified on the child table, save and close, the system will automatically refresh the child table list to display the new child table data row, it is possible to use this child table refresh function to calculate and display the value.

The detailed implementation is described below:

1. Rewrite Subgrid refresh event, Subgrid register an event when refreshing, complete Subgrid item's cumulative calculation

  1: (function (window, undefined) {
  2:     var prerefresh = Mscrm.GridControl.prototype.Refresh;
  3:     function () {
  4:         prerefresh.apply (this);
  5:         firecallback.apply (this);
  6:     }
  7:     var oneevent = null;
  8:     function (JSON) {
  9:         oneevent = json;
Ten:     }
One:     function firecallback () {
:         if (oneevent && oneevent.controlid && oneevent.controlid = = this.get_id ()) {
:             oneEvent.callback.apply (this, null);
:         }
:     }
:}) (window);
18:mscrm.gridcontrol.add_onrefresh ({
:     controlId: "chart_btl_postmfunction () {
:         sumcost ("new_sum_cost_bp", "new_cost", "new_btl_posm");
:     }
22:});
The Sumcost method here is to calculate and display the value on the main table
2. Calculating and Displaying methods
  function sumcost (Sumfieldnmae, Subfiledname, Subentityname) {
  2:     var amount = 0;
  3:     var key = "new_marketing_planid/id";
  4:     var value = Xrm.Page.data.entity.getId ();
  5:     //var query = "new_btl_posmset? $select =new_cost& $filter =new_marketing_planid/id eq GUID ' 123 ' ";
  6:     var query = subentityname + "Set? $select =" + subfiledname + "& $filter =" + key + " eq GUID '+ value + ' ';
  7:     var result = Odataretrieve (query);
  8:     if (result! = null && result.results.length > 0) {
  9: For          (var i = 0; i < result.results.length; i++) {
Ten:             Amount + = number (result.results[i].new_cost);
One:         }
:     }
:     Xrm.Page.getAttribute (Sumfieldnmae). SetValue (amount);
15:}
3. Add the JS file to the form, refresh the page, you can see the effect immediately
Dynamic CRM 2013 Learning Notes Series Rollup

Dynamic CRM 2013 Learning Notes (11) using JavaScript to implement child table totals (summary, sum) functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.