locked
JavaScript Updates RRS feed

  • Question

  • I have a bit of a problem, I have a field that sums a number of other fields running onLoad.  Obviously when I come to report on this field there is no value stored! 

    Is there a way that I can easily go back through the thousands of activities already saved to save the field value???

    Thanks.


    Thursday, March 20, 2014 3:49 PM

Answers

  • Is the field configured as read only on the form?

    If so, you need to add to your script to make sure it gets included in the save event:

    Xrm.Page.getAttribute("nameOfYourCalculatedField").setSubmitMode("always");

    As for the saved ones, that sounds like you have problem. Are you using CRM 2011 or later? You could export the old records to Excel and include the necessary fields, and the calculated one. When exporting, tick the box for "make this data available to reimport". Do the calculation in an extra column in the excel spreadsheet then copy > paste values over the calculated column and delete your temporary workings-out. Re-import and away you go. If these are closed activities, you will have to do a bit more work to achieve this, as you won't be able to update them directly (pretty sure that is the case, anyway).


    Hope this helps.
    Adam Vero, Microsoft Certified Trainer | Microsoft Community Contributor 2011
    UK CRM Guru Blog

    • Proposed as answer by Adam Vero Monday, March 31, 2014 7:29 PM
    • Marked as answer by RoarCRM Monday, June 30, 2014 12:39 PM
    Thursday, March 27, 2014 4:41 PM

All replies

  • Is it possible to use a workflow to handle this calculation? Otherwise there isn't a way using only JavaScript to handle this as JavaScript needs the record open to run.

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Thursday, March 20, 2014 3:59 PM
    Moderator
  • The calculation actually includes division too, so I'm not sure I can run a workflow on all the saved activities?  Is there another way?
    Thursday, March 27, 2014 1:08 PM
  • Is it dividing by a constant (eg value x probability / 100)? If so, you may be able to switch that to multiply by the reciprocal ie 0.01

    You also say "Obviously when I come to report on this field there is no value stored". I am not sure why this is obvious? If your field is set by calculating a value, why is it not then saved?


    Hope this helps.
    Adam Vero, Microsoft Certified Trainer | Microsoft Community Contributor 2011
    UK CRM Guru Blog

    Thursday, March 27, 2014 4:18 PM
  • It's dividing two separate fields within the form.  Doesn't seem like I can do it through a workflow?

    The calculation is done in the onload and also onchange event of the two fields, I presumed that the calculated value would save but it hasn't done for any of them.  

    Thursday, March 27, 2014 4:36 PM
  • Is the field configured as read only on the form?

    If so, you need to add to your script to make sure it gets included in the save event:

    Xrm.Page.getAttribute("nameOfYourCalculatedField").setSubmitMode("always");

    As for the saved ones, that sounds like you have problem. Are you using CRM 2011 or later? You could export the old records to Excel and include the necessary fields, and the calculated one. When exporting, tick the box for "make this data available to reimport". Do the calculation in an extra column in the excel spreadsheet then copy > paste values over the calculated column and delete your temporary workings-out. Re-import and away you go. If these are closed activities, you will have to do a bit more work to achieve this, as you won't be able to update them directly (pretty sure that is the case, anyway).


    Hope this helps.
    Adam Vero, Microsoft Certified Trainer | Microsoft Community Contributor 2011
    UK CRM Guru Blog

    • Proposed as answer by Adam Vero Monday, March 31, 2014 7:29 PM
    • Marked as answer by RoarCRM Monday, June 30, 2014 12:39 PM
    Thursday, March 27, 2014 4:41 PM
  • Thanks for that Adam.  I've added the line of code to the onsave event. 

    Unfortunately the previous Service Activities are all closed - how can I get around this problem? 

    Many thanks again.

    Tuesday, April 1, 2014 9:36 AM