locked
How can I display totals in Header? RRS feed

  • Question

  • Hi,

    I have a field on my form which displays total value of other field values. I want it to display it on header for easy viewing.

    When I kept the field on header, I found it isn't displaying the total value. What shall i do to make it work? Thanks in advance.

    Venkat

    Tuesday, September 18, 2012 5:52 AM

Answers

  • Hi venkal,

    i am using below javascript code and it is register on Onchange event of netprice and taxamount fields. it is working fine for me. just get the header label client id from IE for me it is "header_totalcost_d". it should work.

    function Calculatetotal()
    {
    var formType = Xrm.Page.ui.getFormType();
    var netPrice = Xrm.Page.getAttribute("netprice").getValue();
    var taxAmount = Xrm.Page.getAttribute("taxamount").getValue();
    var totalCost = netPrice + taxAmount;
    Xrm.Page.getAttribute("totalcost").setValue(totalCost);
    document.getElementById('header_totalcost_d').childNodes[0].innerText = totalCost.toString();
    }

    Thanks,

    Shaleen

    • Marked as answer by Venkat1986 Friday, September 21, 2012 5:43 AM
    • Unmarked as answer by Venkat1986 Friday, September 21, 2012 5:44 AM
    • Marked as answer by Venkat1986 Sunday, September 23, 2012 11:09 PM
    Thursday, September 20, 2012 5:22 AM
  • Hi Venkat,

    I strongly agree with david that its an upsupported way but in CRM 2011 SDk we dont have any supported way to fulfill this kind of requirements.

    Still if you want to follow this process. Please open Developer Tools in IE ang get the id as below and use the javascript code provided earlier.

    Thanks,

    Shaleen

    • Marked as answer by Venkat1986 Friday, September 21, 2012 5:43 AM
    • Unmarked as answer by Venkat1986 Friday, September 21, 2012 5:44 AM
    • Marked as answer by Venkat1986 Sunday, September 23, 2012 11:09 PM
    Friday, September 21, 2012 5:08 AM

All replies

  • Hi Venkat1986

    Are you setting the value of the field in JScript?

    If so the value will only display if you save the value to the field.

    An other option is to use the document.getElementById to set the value for the field in the header.

    Tuesday, September 18, 2012 6:40 AM
  • Hi Venkal,

    Please use below code for your requirement:

    function Calculatetotal()
    {
    var formType = Xrm.Page.ui.getFormType();
    if(formType == 2)
    {
    var netPrice = Xrm.Page.getAttribute("netprice").getValue();
    var taxAmount = Xrm.Page.getAttribute("taxamount").getValue();
    var totalCost = netPrice + taxAmount;
    var HeaderText = document.getElementById('header_totalcost_c').childNodes[0].innerText;  // get the current text of the header field
    Xrm.Page.getAttribute("totalcost").setValue(totalCost);   //set total cost value on the form
    document.getElementById('header_totalcost_c').childNodes[0].innerText = HeaderText + " " + totalCost.toString();  //set total cost value in the header
    }
    }

     

    Thanks,

    Shaleen

    • Proposed as answer by Shaleenb Tuesday, September 18, 2012 7:04 AM
    Tuesday, September 18, 2012 7:00 AM
  • Thanks for your reply.

    My totals getting displayed on the body of the form.

    My requirement is I want to display the field total on Body of the form as well as on header of the form. So that if I scroll up or down the form, I shall be abe to see the total.

    I found the schema names of the field are same. So I expected the result automatically shows on header. But it isn't.

    According to your code, does it work if i put header before the field name?

    Venkat


    • Edited by Venkat1986 Wednesday, September 19, 2012 1:25 AM
    Wednesday, September 19, 2012 1:22 AM
  • Can anyone pls help me to fix the issue?
    Wednesday, September 19, 2012 11:02 AM
  • Hi venkal,

    i am using below javascript code and it is register on Onchange event of netprice and taxamount fields. it is working fine for me. just get the header label client id from IE for me it is "header_totalcost_d". it should work.

    function Calculatetotal()
    {
    var formType = Xrm.Page.ui.getFormType();
    var netPrice = Xrm.Page.getAttribute("netprice").getValue();
    var taxAmount = Xrm.Page.getAttribute("taxamount").getValue();
    var totalCost = netPrice + taxAmount;
    Xrm.Page.getAttribute("totalcost").setValue(totalCost);
    document.getElementById('header_totalcost_d').childNodes[0].innerText = totalCost.toString();
    }

    Thanks,

    Shaleen

    • Marked as answer by Venkat1986 Friday, September 21, 2012 5:43 AM
    • Unmarked as answer by Venkat1986 Friday, September 21, 2012 5:44 AM
    • Marked as answer by Venkat1986 Sunday, September 23, 2012 11:09 PM
    Thursday, September 20, 2012 5:22 AM
  • Venkat,

    FYI, anytime you see 'getElementById' code, that means it is not supported code.  (You won't find it in the SDK).

    The header values can be updated through script, as long as you have the field on the form as well.  But header values are not updated via onChange events.  They also cannot be updated through onLoad events.  So, that field will not show the current total as you are working the form, only when you save or re-open the record. 

    HTH,

    Dave

    Thursday, September 20, 2012 3:23 PM
  • @Shaleen: On my form, the header and body Total cost field has the same schema name. I am using CRM on premise. Is it a reason for the not getting header_schema name?

    @David:  Can you please provide me the script to show the javascript based field replica on header?

    Friday, September 21, 2012 4:46 AM
  • Hi Venkat,

    I strongly agree with david that its an upsupported way but in CRM 2011 SDk we dont have any supported way to fulfill this kind of requirements.

    Still if you want to follow this process. Please open Developer Tools in IE ang get the id as below and use the javascript code provided earlier.

    Thanks,

    Shaleen

    • Marked as answer by Venkat1986 Friday, September 21, 2012 5:43 AM
    • Unmarked as answer by Venkat1986 Friday, September 21, 2012 5:44 AM
    • Marked as answer by Venkat1986 Sunday, September 23, 2012 11:09 PM
    Friday, September 21, 2012 5:08 AM
  • You rock Shaleen.

    It is working :)

    Friday, September 21, 2012 5:43 AM
  • What should I do inorder to get dollar sign before the value?
    Friday, September 21, 2012 5:45 AM
  • if your field is Currency field then on form it will take care about the $ sign automatically but for header:

    Append the header label as by adding $ in begining.

    document.getElementById('header_totalcost_d').childNodes[0].innerText = "$" + totalCost.toString();

    Please mark as answer if it helps.

    Thanks,

    Shaleen

    Friday, September 21, 2012 6:03 AM
  • Thats a really great resource man, just now i am also searching code like that... thank you Shaleenb :)

    i have test project with Xhtmlchamps actually 

    Friday, September 21, 2012 5:28 PM