CRM 2011 Wont Save Value Of Calculated Field! HELP!

Proposed CRM 2011 Wont Save Value Of Calculated Field! HELP!

  • 9 czerwca 2012 20:57
     
     

    Hey Guys,

    Ive wasted an incredible amount of time trying to create something very simple. I've created a custom calculated field within a form in CRM 2011. What is is supposed to do is add the totals from several different fields and then populate the total field with the result. I have very little experience with Javascript, but I managed to come up with some code that makes the field do exactly what it was supposed to do: add the fields and display the answer. The problem is IT WONT SAVE THE RESULT!!!  Ive been searching all over for an answer and Ive tried dozens of different things and I cant get it to save the value! Ill click save and close and as soon as I come back, the calculated field is blank again. I would REALLY appreciate some help with this.

    This is the code I have entered into the OnLoad of the form that does the addition needed but will not save the result:

    function setupEvents()
    {
    crmForm.all.new_prospectrating1.attachEvent ("onkeyup", doCalc);
    crmForm.all.new_prospectrating2.attachEvent ("onkeyup", doCalc);
    }
    function doCalc()
    {
    var pr1= parseFloat(crmForm.all.new_prospectrating1.value)
    var pr2= parseFloat(crmForm.all.new_prospectrating2.value)
    var total = pr1+pr2
    crmForm.all.new_total.value = total
    }

    As you can see, Im adding ProspectRating1 and ProspectRating2 and showing the result in Total. This works fine. If you could help me figure out how to save the result I would be eternally greatful. Thanks.

    John

Wszystkie odpowiedzi

  • 9 czerwca 2012 20:52
     
     

    Hey Guys,

    Ive wasted an incredible amount of time trying to create something very simple. I've created a custom calculated field within a form in CRM 2011. What is is supposed to do is add the totals from several different fields and then populate the total field with the result. I have very little experience with Javascript, but I managed to come up with some code that makes the field do exactly what it was supposed to do: add the fields and display the answer. The problem is IT WONT SAVE THE RESULT!!!  Ive been searching all over for an answer and Ive tried dozens of different things and I cant get it to save the value! Ill click save and close and as soon as I come back, the calculated field is blank again. I would REALLY appreciate some help with this.

    This is the code I have entered into the OnLoad of the form that does the addition needed but will not save the result:

    function setupEvents()
    {
    crmForm.all.new_prospectrating1.attachEvent ("onkeyup", doCalc);
    crmForm.all.new_prospectrating2.attachEvent ("onkeyup", doCalc);
    }
    function doCalc()
    {
    var pr1= parseFloat(crmForm.all.new_prospectrating1.value)
    var pr2= parseFloat(crmForm.all.new_prospectrating2.value)
    var total = pr1+pr2
    crmForm.all.new_total.value = total
    }

    As you can see, Im adding ProspectRating1 and ProspectRating2 and showing the result in Total. This works fine. If you could help me figure out how to save the result I would be eternally greatful. Thanks.

    John

  • 9 czerwca 2012 21:41
     
     Proponowana odpowiedź

    Please Try Xrm.Page.data.entity.save() under your last operation to save the entity.

    Why aren't you using the XRM page model. It's much simpler than your code. http://technet.microsoft.com/en-us/library/gg334720.aspx#BKMK_save

    Here is a post I created a while ago for a caclulated field in CRM 2011 

    http://mshelp.be/creating-a-calculated-field-in-dynamics-crm2011-356.htm

    PS/ Please don't double post

    • Zaproponowany jako odpowiedź przez Sven Vanoirbeek 9 czerwca 2012 21:41
    •  
  • 9 czerwca 2012 21:42
     
     
  • 10 czerwca 2012 08:12
     
     

    I would say move to Xrm.Page as crmForm may not work in future releases.

    Try something like this

    //Update field
    Xrm.Page.getAttribute("new_total").setValue(value);  
    //Set submit mode to always
    Xrm.Page.getAttribute("new_total").setSubmitMode("always"); 
    //Force save
    Xrm.Page.data.entity.save();  

    I hope this helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com

  • 11 czerwca 2012 05:23
     
      Zawiera kod

    Have you disabled the total attribute on teh form? Or made it readonly?

    You need to explicitly submit this field to database using the following code

    attributeobj.setSubmitMode("always");

    Sample code from the SDK below.

    submitAllOptionsetData: function ()
    {
        var attributes = Xrm.Page.data.entity.attributes.get(SDK.AttributeSamples.isOptionSet);
        for (var i in attributes)
        {
            attributes[i].setSubmitMode("always");
        }
    
        alert(Xrm.Page.data.entity.getDataXml());
    },

    HTH

    Sam


    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

  • 11 czerwca 2012 08:42
     
     Proponowana odpowiedź Zawiera kod

    You are missing ";" at the end of statements and you are using the syntax of CRM 4.0. Try following on change of field than make it work on Load for Keyup event:-

    function setupEvents() {
        crmForm.all.new_prospectrating1.attachEvent("onkeyup", doCalc);
        crmForm.all.new_prospectrating2.attachEvent("onkeyup", doCalc);
    }
    
    function doCalc() {
        var pr1 = Xrm.Page.getAttribute("new_prospectrating1").getValue();
        var pr2 = Xrm.Page.getAttribute("new_prospectrating2").getValue();
        var total = pr1 + pr2;
        Xrm.Page.getAttribute("new_total").setValue(total);
        Xrm.Page.getAttribute("new_total").setSubmitMode("always");
    }


    Regards Faisal

    • Zaproponowany jako odpowiedź przez Adam Vero 11 czerwca 2012 16:14
    •