Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

addOnStageChange() called twice

I have written an event handler on change of stage in BPF in Opportunity Entity:

var checkForAccountApproved = function (executionContext) {
    var formContext = executionContext.getFormContext();
   formContext.data.process.addOnStageChange(function (stageContext) {

        var stageName = stageContext.getEventArgs().getStage().getName().toString();
        if (some conditions) {
            formContext.data.process.movePrevious();

        }
        else {
            currentActiveStage.setValue(stageName);
            formContext.data.entity.save();
        }

    });
};

Basically, on clicking next, I need to check if some conditions are not satisfied, then only, the next stage should be active, else, the current stage should be active.

If the conditions are not satisfied, i.e. the stage change happens, I will store the value of the current active stage in a field. If I am explicitly calling save, the event handler is again triggered.

Why is it so?

like image 530
Richa Tibrewal Avatar asked Oct 14 '25 03:10

Richa Tibrewal


1 Answers

Probably a late answer but ... don't use formContext.data.process.movePrevious() to cancel your stage change, as this will try to move the stage back and re-execute your pre-stage change ( this will probably keep looping till you get back to the first stage).. Instead use the below which cancels the stage change and stays at the current stage

executionContext.getEventArgs().preventDefault();

like image 186
Charles Osei Avatar answered Oct 16 '25 16:10

Charles Osei