locked
CRM Online, why stageChangeEvent() handler be triggered twice RRS feed

  • Question

  • Hi,

    I am working on customization of a business process workflow which triggers stageChangeEvent() when user clicks on Next Stage or Previous Stage.  However, I noticed that stageChangeEvent() was triggered two times with each one click on Next Stage.  It causes problem in the javascript code running within the handler.  Do anyone know why and how to prevent stageChangeEvent() from being triggered twice?  Thanks.

    Tuesday, June 14, 2016 8:26 PM

Answers

  • Hi

    It should not trigger twice. In my CRM I didn't observe the issue.

    May be you need to check your code?

    May be you can debug and find out the issue why it is triggering twice.

    • Marked as answer by chicago bq Friday, June 17, 2016 9:17 PM
    Friday, June 17, 2016 3:47 PM

All replies

  • Hi

    It should not trigger twice. In my CRM I didn't observe the issue.

    May be you need to check your code?

    May be you can debug and find out the issue why it is triggering twice.

    • Marked as answer by chicago bq Friday, June 17, 2016 9:17 PM
    Friday, June 17, 2016 3:47 PM
  • Hi, Balu05-

    Yes, you're absolutely right.  I found out this issue resolvable by adding one line of conditional code.  It triggers twice when a new, say lead, loaded and saved.  Form onLoad adds "Xrm.Page.data.process.addOnStageSelected(stageSelectedEvent);" once, and Form onSave adds "Xrm.Page.data.process.addOnStageSelected(stageSelectedEvent);" another time.

    In order to avoid trigger it twice, add condition like the code below:

     if (Xrm.Page.data.entity.getId() != null && Xrm.Page.data.entity.getId() != "")
     {
           Xrm.Page.data.process.addOnStageSelected(stageSelectedEvent);
           Xrm.Page.data.process.addOnStageChange(stageChangeEvent);
     }
       

    Friday, June 17, 2016 9:17 PM
  • It should not!

    If you're adding custom logic in between stages, please check/review, the event handler has been added/registered on both onLoad or onSave or not.


    • Edited by Niloy_Gourh Saturday, June 18, 2016 11:01 AM
    Saturday, June 18, 2016 11:01 AM