locked
saving attribute fields on entity's OnLoad event RRS feed

  • Question

  • I placed this snippet of code in the OnLoad event of my entity to do some calculations and set it to the appropriate form fields, but I am having difficulty saving it.

     

    Here's the code:

     

    Code Snippet

    var hoursElapse = TimeElapse();
    crmForm.all.new_activehours.DataValue = hoursElapse;

     

    var Score = CalculateScore(hoursElapse);
    crmForm.all.new_score.DataValue = Score;

     

    crmForm.Save();

     

     

    TimeElapse() is a function that takes the date and time now and subtracts it from the date and time of this new account and returns the number of hours that has past since the account was created.

     

    I then assign it to the Active Hours field and call another function to do some more math.  I then use "crmForm.Save" to save the results into SQL so that I could trigger a history, but when I check the SQL column for these 2 values, they are both still null.  Of course, the OnLoad() event is displaying the numbers correctly, but it is not saving, even if i hit the account's save button, i don't see the values on SQL.

     

    Is there a way to save these calculated values?

     

    Thanks.

     

    Tuesday, March 11, 2008 10:38 PM

Answers

  • I suspect the problem might be that you have set the ActiveHours field (and your other field) to be read-onlt on your form (which seems logical since you only want the field to be updated by your functions, not by the users).

    By default, a read-only field does not get saved to the database. If you want to save a read-only field, you must first set its ForceSubmit property = true, eg:

    Code Snippet

    crmForm.all.new_activehours.ForceSubmit = true;


    Regards

    Greg Owens
    My Blog: http://thecrmgrid.wordpress.com
    Tuesday, March 11, 2008 11:32 PM

All replies

  • I suspect the problem might be that you have set the ActiveHours field (and your other field) to be read-onlt on your form (which seems logical since you only want the field to be updated by your functions, not by the users).

    By default, a read-only field does not get saved to the database. If you want to save a read-only field, you must first set its ForceSubmit property = true, eg:

    Code Snippet

    crmForm.all.new_activehours.ForceSubmit = true;


    Regards

    Greg Owens
    My Blog: http://thecrmgrid.wordpress.com
    Tuesday, March 11, 2008 11:32 PM
  • Yes!  thank you. this works out perfectly.

     

    Tuesday, March 11, 2008 11:35 PM