web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Changing BPF Stage with JS

(0) ShareShare
ReportReport
Posted on by 1,067

Hi all,

I'm noticing an strange behavior when using JS to change the active BPF stage and I would like to know if I'm doing something wrong. Basically, I have a requeriment on which due to the change of a field, if the new value is "Yes", I need to move the BPF Stage to the next one as the current is already completed. Here's the code I'm using for that:

emScripts.OnPIRFEChange = function () {    
    Xrm.Page.data.save().then(function () {
        var PIRFE =  Xrm.Page.getControl("em_PIRFE").getAttribute();
        if(PIRFE.getValue())
        {           
            Xrm.Page.data.process.moveNext(function (status)
            {               
                // I'm excecuting the code below within the callback method as it is async.
                console.log(status); // Here I get Success.
                var NextStageID = emScripts.GetNextStageID(); // I confirmed that the ID is correct.
                Xrm.Page.data.process.setActiveStage(NextStageID, function (status)
                {
                    console.log(status); // Also here I get Success.
                });
            });    
        }
    }, null);
};

Once the code finishes, I see that the selected and active stage becomes the one I want, however, this only happens for an average of 2 seconds as after that time the Stage is set back to the one I had before(and I can confirm I have no code that does that). So, not sure what I'm doing wrong, I have tried different ways to fix it but none of them worked as if I don't call the methods as described above, I get "Invalid" errors on the console.

Any workarounds? Thanks in advance!

*This post is locked for comments

I have the same question (0)
  • Sabahat Zaman Khan Profile Picture
    5 on at
    RE: Changing BPF Stage with JS

    how to move back stage? From 4 or 5th stage to first stage?

  • Suggested answer
    Macoy Profile Picture
    275 on at
    RE: Changing BPF Stage with JS

    Hi Enrique,

    Try this

    emScripts.OnPIRFEChange = function () {    

       Xrm.Page.data.save().then(function () {

           var PIRFE =  Xrm.Page.getControl("em_PIRFE").getAttribute();

           if(PIRFE.getValue())

           {          

               Xrm.Page.data.process.moveNext(function (status)

               {  

                   console.log(status); // Here I get Success.

                   Xrm.Page.data.refresh();

               });    

           }

       }, null);

    };

    Regards,

    Macoy

  • EnriqueMdz Profile Picture
    1,067 on at
    RE: Changing BPF Stage with JS

    Hi Sravan, first of all thanks for your answer. Calling only Xrm.Page.data.process.moveNext() ends up with the same behavior, while calling only setActiveStage returns an "Invalid" error. Actually, the only way I found to make setActiveStage to work properlly("Success") was to call it same as in the example above. I tried to see if there was another component doing an update to the stage using Audit History, but the last change(the one that makes the stage to return to the old one) does not appear, so not sure if this could be a bug.

  • Sravan Kumar Chandhavolu Profile Picture
    140 on at
    RE: Changing BPF Stage with JS

    Hi Enrique,

    I have a question for you, actually when you call Xrm.Page.data.process.moveNext(), it would not only advance the current stage but also make it active. In which case, you don't need to call setActiveStage again as that would be redundant. But if you are looking to directly leap to a stage which is not immediate, in that case, you can utilize setActiveStage. Does that make sense? Can you try that?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans