Skip to main content

Notifications

Announcements

No record found.

Customer Service forum

How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

Posted on by 60

I have four Stages such as Stage A, Stage B, Stage C and Stage D.

When the current stage is Stage C, I don't want to allow the user to move back to previous stages like Stage A and Stage B.

I want to disable Dynamic CRM's default "Previous" button's action. 

Is it available or not ?

Please help me.

I am still trying on this. I can't get it till now.

Thanks in advance

Categories:
  • Suggested answer
    Rick Wilson Profile Picture
    Rick Wilson 15 on at
    RE: How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

    If you are utilizing the UCI interface there is a new JavaScript handler available for the Business Process Flows (BPF), onPreStageChange.  Unlike the onStageChange handler onPreStageChange fires before the actual business process has been changed so that you can evaluate if you want the change to occur and prevent it if needed.

    With this new handler we can now get rid of many of the Synchronous workflows used previously to evaluate the changes made to a BPF.  By removing these workflows the overall performance of your BPF changes should be increased.  Additionally calling JavaScript code being before the change also eliminates additional problems such as the users clicking the Next/Previous multiple times before the workflows have been fired (Tip #360

    To utilize the new handler you will needed to create a function and then pass that function into the addOnPreStageChange function provided under executionContext.getFormContext().data.process.  It is best practice to pass a function rather than using an anonymous function because it will allow you to remove the handler later if needed.  Additional documentation for these function can be found here

     function onLoad(executionContext) {
            var formContext = executionContext.getFormContext();
            var process = formContext.data.process;        
    
            //handles changes to the BPF before they actually occur
            process.addOnPreStageChange(myProcessStateOnPreChange);
        }
    
    function myProcessStateOnPreChange() {
    
            var formContext: Xrm.FormContext = executionContext.getFormContext();
            var process = formContext.data.process;
            var eventArgs = executionContext.getEventArgs();
    
            var currentStageId = process.getActiveStage().getId();
            var nextStageId = process.getSelectedStage().getId();
    
            //dont allow to go back using the set active button
            if (currentStageId != nextStageId) {
                eventArgs.preventDefault();
                Xrm.Utility.alertDialog("You cannot use the Set Active button.")
                return;
            }        
                  
            if (eventArgs._direction === 1) //backwards
            {            
                //here you can add logic based upon the BPF going to the previous Stage.
                return;
            }
    
            //otherwise forward
            // here you can add logic based upon the BPF going to the next Stage.   
        }


    https://www.richardawilson.com/2019/10/dynamics-bpf-javascript-new.html
  • Kyi Moh Profile Picture
    Kyi Moh 60 on at
    RE: How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

    Hi Leo,

    Thanks for your answer.

    I got it by using background workflow.

    Best Regards,

    Kyi Moh

  • Verified answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

    Hi Kyi Moh,

    Js and plugins may have conflicting errors, you could try workflow to automatically move stages based on field value.

    blogs.msdn.microsoft.com/.../automate-business-process-flow-stages-using-workflows

    Hope it helps.

    Best Regards,

    Leo

  • Kyi Moh Profile Picture
    Kyi Moh 60 on at
    RE: How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

    Hi Priyesh Wagh,

    I have still one problem, our client requirement is to move stage automatically  from coding not user action.

    For example, user can't move next/previous at Stage C. But, it will move programmatically from Stage C to Stage D based on hidden field value changed.

    I tried it using javascript function moveNext(). But as you said, plugin exception block form level javascript function.

    So, could you please suggest me to move stage in coding or any other way?

    I found that some guys suggest to update traversedPath .

    But, my problem is that I can't use stageid as hardcode to update traversedPath.

    In this case I can only know active stage name.

    Please help me.

    Best Regards,

    Kyi Moh  

  • Priyesh Profile Picture
    Priyesh 7,392 User Group Leader on at
    RE: How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

    Oh Wow! I'm glad to know that :)

    Cheers.

  • Kyi Moh Profile Picture
    Kyi Moh 60 on at
    RE: How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

    Hi  Priyesh Wagh,

    I am really thanks to you so much.

    I got it the way you supposed using Plugin and create custom field Stage Name.

    Thanks you so much again.

    Best Regards,

    Kyi Moh

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

    Hi Moh,

    It is supported in D365, the instance supports Native JS code, and I tried in my instance and it worked.

    You could follow my steps and have a try.

    Best Regards,

    Leo

  • Verified answer
    Priyesh Profile Picture
    Priyesh 7,392 User Group Leader on at
    RE: How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

    Hi Kyi,

    Sure, so here's the following instructions/highlights on what you can do -

    1. The record you run on can have a Stage Name field (previously, this existed but was recently deprecated). To work around this problem on what Stage the record is, follow this blog of mine - d365demystified.com/.../bpf-process-stage-name-not-populating-on-records-in-d365-v9-deprecated-and-workaround

    2. So let's say, you have the field correctly working on the record in terms of storing the stage name mentioned in the blog in #1 above.

    3. Write a plugin on post-operation of the record. This should be a synchronous plugin because you want to throw error to the user on screen. The filtering attribute for the plugin registration step will be the stage name field mentioned in the blog.

    4. When the plugin runs, check in context what was the Stage Name was changed to - i.e. "Stage A" or "Stage B", then check in pre-Image, if the value of that field was "Stage C" - this means you want to restrict the user now.

    5. Once the point in #4 above holds true, throw an exception using throw new InvalidPluginExecutionExection("Sorry, you cannot move back to " + Stage Name (from the context));

    Now, because this is a synchronous plugin, the record will not be saved even if it is registered in the post image if it correctly captures your exception.

    Also, even if someone tries to change the name from the back-end, the plugin will work as opposed to JS that can only work on form.

    I really hope this helps you. Pardon me for being short and on a high level of approach.

    Thanks!

  • Kyi Moh Profile Picture
    Kyi Moh 60 on at
    RE: How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

    Hi Priyesh Wagh,

    Thanks for your answer.

    Could you please suggest me more detail  steps about using Plugin?

    Now, I will try to move my way to use Plugin.

    Best Regards,

    Kyi Moh

  • Kyi Moh Profile Picture
    Kyi Moh 60 on at
    RE: How To Stop/Pause/Prevent "Previous Stage" Button on Business Process Flow Using Supported Way

    Hi Leo,

    Thanks for your next answer.

    Is it supported code ?

    I think that it's not the supported code.

    Best Regards,

    Kyi Moh

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans