locked
Field updated by Script in Form is not refelected in RRS feed

  • Question

  • <Edit: I think I originally posted this in wrong forum. Hence posting again>

    Hi Gurus,

    to fulfil an internal requirement I have created a "Revenue Projection" entity to allow sales user to populate revenue split by month and associated this entity to Opportunity. Then I wrote an script on the Opportunity Form to total the Monthly Revenue Split Columns and update the "Est. Revenue" field on the Opportunity. This works fine and the total of all the months of splitted revenue is visible for any record on Opportunity Form. BUT the sum total is not refelected when I see the same record in Default Public View i.e. "My Open Opportunities". This view still shows old values and not the updated sum totals.
    - I have tried sign-out/sign-in even reboot.
    - I have made sure that the column/field for both form and public view is exactly the same i.e. 'estimatedvalue'
    - I also noticed that the revenue totals are not reflected in any other views like Advanced Find, My Open Opportunities, Open Opportunities. The correct total is visible only in Form where it is being updated by the script.

    The script is on OnLoad and I am just in test phase explicitly saving Revenue Projection, Opportunity etc. Once I save Opportunity the Opportunity form shows the updated total (as it runs the script written on Opportunity Form). I then save and close opportunity and view the same record in the Open Opportunity View but the Est. Revenue field is not updated there. I even tried refreshing and re-quering the record but still the view shows the old Est. Total.


    Thank you in advance!

    For your reference, I am attaching the script I have written on Form Load Event of the Opportunity Form. (CRM 4.0)


    //  Define Variables
        var sOptyId;
        var CRM_FORM_TYPE_UPDATE = 2; //to execute the logic only in Form Update Mode
        var sAuthenticationHeader;
        var sXML;
        var sResultXML;
        var xmlHttpRequest;
        var oXmlDoc; //xml document for parsing the result
        var businessEntities;

        var iJanRev = 0;
        var iFebRev = 0;
        var iMarRev = 0;
        var iAprRev = 0;
        var iMayRev = 0;
        var iJunRev = 0;
        var iJulRev = 0;
        var iAugRev = 0;
        var iSepRev = 0;
        var iOctRev = 0;
        var iNovRev = 0;
        var iDecRev = 0;
        var iTotalRevenue = 0;

        

     

    //  As sales people would enter monthly detail in Revenue Projection (associated entity), there will
    //  no need to populate or updated est. Total Revenue. Hence relevant fields on the form will be
    //  disabled.
        crmForm.all.estimatedvalue.Disabled = true;
        crmForm.all.isrevenuesystemcalculated.Disabled = true;


    //  The details will be processed only if the form was open in updated mode. For the first time i.e. when the form
    //  is in 'Create' mode, do nothing!

        if (crmForm.FormType == CRM_FORM_TYPE_UPDATE)
        {
          //  Store the Opportunity Id to retreive relevant "Revenue Projections"
              sOptyId = crmForm.ObjectId;

          //  Use the GenerateAuthenticationHeader() method
          //  available from the CRM form to generate the Soap header text.
              sAuthenticationHeader = window.opener.GenerateAuthenticationHeader();

          //  Define the SOAP XML to access Microsoft Dynamics CRM Web service.
              var sXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
              "<soap:Envelope xmlns:soap="+
              "\"http://schemas.xmlsoap.org/soap/envelope/\" "+
              "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
              "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
              sAuthenticationHeader+
              "<soap:Body>" +

          //  Specify the RetrieveMultiple message.
              "<RetrieveMultiple xmlns="+
              "\"http://schemas.microsoft.com/crm/2007/WebServices\">" +

          //  Specify that this is a QueryByAttribute query.
              "<query xmlns:q1="+
              "\"http://schemas.microsoft.com/crm/2006/Query\" "+
              "xsi:type=\"q1:QueryByAttribute\">" +

          //  Query the Revenue Projection Entity
              "<q1:EntityName>new_revenueprojection</q1:EntityName>" +

          //  Set the columns you want to return.
              "<q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
              "<q1:Attributes>" +
              "<q1:Attribute>new_janrev</q1:Attribute>" +
              "<q1:Attribute>new_febrev</q1:Attribute>" +
              "<q1:Attribute>new_marrev</q1:Attribute>" +
              "<q1:Attribute>new_aprrev</q1:Attribute>" +
              "<q1:Attribute>new_mayrev</q1:Attribute>" +
              "<q1:Attribute>new_junrev</q1:Attribute>" +
              "<q1:Attribute>new_julrev</q1:Attribute>" +
              "<q1:Attribute>new_augrev</q1:Attribute>" +
              "<q1:Attribute>new_seprev</q1:Attribute>" +
              "<q1:Attribute>new_octrev</q1:Attribute>" +
              "<q1:Attribute>new_novrev</q1:Attribute>" +
              "<q1:Attribute>new_decrev</q1:Attribute>" +
              "</q1:Attributes>" +
              "</q1:ColumnSet>" +

          //  Specify the attribute that you are querying on.
              "<q1:Attributes>" +
              "<q1:Attribute>new_revenueprojectionidid</q1:Attribute>" +
              "</q1:Attributes>" +

          //  Set the value of the attribute using the OptyId
              "<q1:Values>" +
              "<q1:Value xsi:type=\"xsd:string\">"+
              sOptyId+
              "</q1:Value>" +
              "</q1:Values>" +
              "</query>" +
              "</RetrieveMultiple>" +
              "</soap:Body>" +
              "</soap:Envelope>";

          //  Create an instance of an XMLHTTP object.
              xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

          //  Configure the XMLHttp object for the Microsoft CRM Web services.
              xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
              xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
              xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
              xmlHttpRequest.setRequestHeader("Content-Length", sXML.length);

          //  Send the XMLHttp request.
              xmlHttpRequest.send(sXML);

          //  Capture the XMLHttp response in XML format.
              sResultXML = xmlHttpRequest.responseXML;

          //  Create an XML document that you can parse.
              oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
              oXmlDoc.async = false;

          //  Load the document that has the results.
              oXmlDoc.loadXML(sResultXML.xml);

          //  Get only the BusinessEntity results.
              businessEntities = oXmlDoc.getElementsByTagName('BusinessEntity');

          //  Loop through the BusinessEntity elements.
              for (i=0;i < businessEntities.length;i++)
              {
                  iJanRev = businessEntities[i].selectSingleNode('./q1:new_janrev')
                  iTotalRevenue = iTotalRevenue + ((iJanRev == null)? 0 : parseInt(iJanRev.text))
                  iFebRev = businessEntities[i].selectSingleNode('./q1:new_febrev')
                  iTotalRevenue = iTotalRevenue + ((iFebRev == null)? 0 : parseInt(iFebRev.text))
                  iMarRev = businessEntities[i].selectSingleNode('./q1:new_marrev')
                  iTotalRevenue = iTotalRevenue + ((iMarRev == null)? 0 : parseInt(iMarRev.text))
                  iAprRev = businessEntities[i].selectSingleNode('./q1:new_aprrev')
                  iTotalRevenue = iTotalRevenue + ((iAprRev == null)? 0 : parseInt(iAprRev.text))
                  iMayRev = businessEntities[i].selectSingleNode('./q1:new_mayrev')
                  iTotalRevenue = iTotalRevenue + ((iMayRev == null)? 0 : parseInt(iMayRev.text))
                  iJunRev = businessEntities[i].selectSingleNode('./q1:new_junrev')
                  iTotalRevenue = iTotalRevenue + ((iJunRev == null)? 0 : parseInt(iJunRev.text))
                  iJulRev = businessEntities[i].selectSingleNode('./q1:new_julrev')
                  iTotalRevenue = iTotalRevenue + ((iJulRev == null)? 0 : parseInt(iJulRev.text))
                  iAugRev = businessEntities[i].selectSingleNode('./q1:new_augrev')
                  iTotalRevenue = iTotalRevenue + ((iAugRev == null)? 0 : parseInt(iAugRev.text))
                  iSepRev = businessEntities[i].selectSingleNode('./q1:new_seprev')
                  iTotalRevenue = iTotalRevenue + ((iSepRev == null)? 0 : parseInt(iSepRev.text))
                  iOctRev = businessEntities[i].selectSingleNode('./q1:new_octrev')
                  iTotalRevenue = iTotalRevenue + ((iOctRev == null)? 0 : parseInt(iOctRev.text))
                  iNovRev = businessEntities[i].selectSingleNode('./q1:new_novrev')
                  iTotalRevenue = iTotalRevenue + ((iNovRev == null)? 0 : parseInt(iNovRev.text))
                  iDecRev = businessEntities[i].selectSingleNode('./q1:new_decrev')
                  iTotalRevenue = iTotalRevenue + ((iDecRev == null)? 0 : parseInt(iDecRev.text))


              }
           
            //alert("Total Revenue is " + iTotalRevenue);
            crmForm.all.estimatedvalue.DataValue = iTotalRevenue;

        }

     

    Tuesday, April 14, 2009 12:46 PM

Answers

  • Hi,

    Sounds very strange.

    I have a feeling that CRM does not detect the change for some reason, or that you show the base value, and not the "local value".

    Is the field read only (they will not update, even if you make a change)? In that case set the forcesubmit flag for the field to True (e.g.) crmForm.all.estimatedvalue.ForceSubmit = true;

    Or is Auto Calc from prodcts turned on for the oppty?

    If not, I would have tested manually change after form load; to see if the field is changed in the lists.

    Does any of this apply?

    Morten




    Tuesday, April 14, 2009 3:05 PM

All replies

  • Hi,

    Sounds very strange.

    I have a feeling that CRM does not detect the change for some reason, or that you show the base value, and not the "local value".

    Is the field read only (they will not update, even if you make a change)? In that case set the forcesubmit flag for the field to True (e.g.) crmForm.all.estimatedvalue.ForceSubmit = true;

    Or is Auto Calc from prodcts turned on for the oppty?

    If not, I would have tested manually change after form load; to see if the field is changed in the lists.

    Does any of this apply?

    Morten




    Tuesday, April 14, 2009 3:05 PM
  • Thanks Morten.. The field was indeed read only and hence your suggestion crmForm.all.estimatedvalue.ForceSubmit = true;  worked!
    Tuesday, April 14, 2009 4:48 PM