locked
Problem with timing events with Javascript. RRS feed

  • Question

  • I have a tricky situation. The scenario is this:

    In the Opportunity Entity, I have a field called "Estimated Revenue". When this is updated with a value, what happens is that a fetchXML query using javascript executes updating the Product Entity field called "Estimated Totals". It does this by using the "SUM" all Estimated Revenue. The Estimated Totals field essentially calculates ALL Opportunity Estimated Revenue fields to give a total. The example better explains:

    [OPPORTUNITY] [Estimated Revenue - $400]
    [OPPORTUNITY] [Estimated Revenue - $300]
    [OPPORTUNITY] [Estimated Revenue - $100]

       |

    [PRODUCTS] [Estimated Totals - $800]

    The problem is; I have this event hooked to the onSave handler. If I make an update to the Estimated Revenue in the Opportunity form, the new value isn't added to the XML query. Essentially the query doesn't take in the new value, until I save it a second time.

    There is a problem with the sequencing of events here, I am wondering what is a better approach to get the form to update first, then get the XML query to run second. 

    Any help appreciated.

    Tuesday, November 12, 2013 9:30 AM

All replies

  • better way to achieve this go with post create/update/delete plugin and do your stuff.


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !

    • Proposed as answer by SravaniRN459 Tuesday, November 12, 2013 12:00 PM
    Tuesday, November 12, 2013 9:36 AM
  • I agree with Vikram that this should be done in a plugin. What would happen if these records came in from some sort of import? They wouldn't fire the javascript.

    However if you do insist on doing it in JavaScript, it sounds like your xml is getting updated on change of the estimated revenue. This will only fire on lose focus. Save will probably not lose focus on extimated revenue , so the xml will not get updated. Add a call to blur on the estimated revenue field in your onsave script.

    Chris

    Tuesday, November 12, 2013 11:55 AM