Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Changing BPF Stage with JS

(0) ShareShare
ReportReport
Posted on by 1,065

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

  • RE: Changing BPF Stage with JS

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

  • Suggested answer
    Macoy Profile Picture
    Macoy 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
    EnriqueMdz 1,065 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.

  • 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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans