locked
Does anyone know of a method to optimise the performance of javascript for single-run functions? RRS feed

  • Question

  • For instance, assuming you just create a record and want to generate an autonumber for an Account ID - you could either add function to the onLoad/Onsave event so that the function gets executed and saved like this:

    function autonumber(){

    if AccountID != null

    //Generate Account Number

    }

    But this function only needs to run once, but here it will get executed every time the form loads or saves, which isn't good from a performance perspective, so does anyone have an idea how to get 

    Sunday, November 24, 2013 7:32 AM

Answers

  • Hi,

    You could check Form type :

    //if Form Type equals to CREATE
    if (Xrm.Page.ui.getFormType() == 1) {
        // Generate auto number
    }


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful ! <br/> Vikram ! <br/> My Blog

    Sunday, November 24, 2013 7:38 AM

All replies

  • Hi,

    You could check Form type :

    //if Form Type equals to CREATE
    if (Xrm.Page.ui.getFormType() == 1) {
        // Generate auto number
    }


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful ! <br/> Vikram ! <br/> My Blog

    Sunday, November 24, 2013 7:38 AM
  • Thank you. Perfect.
    • Proposed as answer by D Suresh Kumar Monday, November 25, 2013 3:15 AM
    Sunday, November 24, 2013 12:01 PM