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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer Service forum

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

(0) ShareShare
ReportReport
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
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Unfortunately there is no supported way to disable/hide the previous button. All the available js methods are mentioned in the below documentation which are supported.

    docs.microsoft.com/.../formcontext-data-process

    I haven't tried it yet but there is an even which triggers on stage change "OnStageChange" which can be used to trigger your custom method. So basically you need to store the current stage somewhere (getActiveStage) and then on stage change check if the new stage is less then the current, if yes then In your custom method, preent the stage change.

    As mentioned I haven't tried it but looks like this should work.

    Other unsupported method is to hide the previous button using jquery-

    ===========

    function HidePreviousButton()

    {

    parent.$("#stageBackActionContainer").hide();

    }

    =============

    Hope this helps.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    You can also use Real Time workflow to set the current stage in a field when status change and then compare that stage with the new stage and cancel the workflow if the stage is new stage is the old stage.

    refer this blog for more detail: https://d365demystified.com/2018/12/24/bpf-process-stage-name-not-populating-on-records-in-d365-v9-deprecated-and-workaround/

  • Suggested answer
    LeoAlt Profile Picture
    16,341 Moderator on at

    Hi partner,

    You could not disable the "Previous"  button, but you could check if the stage move back to previous stages, then prevent the action and alert a notification.

    Here is the sample code for you.

    function preventStage(){
        //get current stage name
        var stage = Xrm.Page.data.process.getActiveStage();
        var name = stage.getName();
        orderNow=getstageOrder(name);//Set a global variable
        Xrm.Page.data.process.addOnStageChange(checkStage);
    }
    
    function checkStage(context){
        //get stage name after stage changes
        var stage = Xrm.Page.data.process.getActiveStage();
        var name = stage.getName();
        var orderafterChagne=getstageOrder(name);//get the stage order after change the stage
        if(orderafterChagne<orderNow){//If orderafterChagne<orderNow, it means the user wants to go pervious stage and then the code will prevent this action
            Xrm.Page.ui.setFormNotification("You could not return to pervious stages", "INFO", "2001"); // Set notification
            context.getEventArgs().preventDefault();
        }
        
    }
    
    //Create a function to get the order by stageName
    function getstageOrder(stageName){
        //Create a List to store the order of stages.
        var stageList=new Array();
        stageList[0]="A";
        stageList[1]="B";
        stageList[2]="C";
        stageList[3]="D";
        for(var i=0;i<stageList.length;i++){
            if(stageList[i]==stageName){
                return i;
            }
        }
    }


    You just need to add this js code to form and add "preventStage" function to "Onload" event.

    community183.png

    Remember to select "pass execution context as first parameter".

    Hope it helps.

    Best Regards,

    Leo

  • Kyi Moh Profile Picture
    60 on at

    Hi Leo,

    Thanks you very much for answer.

    I tried the JS code you provided.

    But, it was not working properly that I want.

    It still move back to "Previous Stage" when I click the previous button.

    Best Regards,

    Kyi Moh

  • Kyi Moh Profile Picture
    60 on at

    Hi Ravi Kashyap,

    Thank you very much for your answer.

    I just want to know how to prevent the stage change move back action.

    Best Regards,

    Kyi Moh

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Did you try context.getEventArgs().preventDefault(); as suggested by Leo?

  • Kyi Moh Profile Picture
    60 on at

    Hi Ravi Kashyap,

    Yes, I tried it by using context.getEventArgs().preventDefault();

    But I found that  preventDefault() is only for saving.

    Please check the below link docs.microsoft.com/.../preventdefault

    Best Regards,

    Kyi Moh

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Okay. Then I guess workflow option may work. Check my response above.

  • Kyi Moh Profile Picture
    60 on at

    Hi Ravi Kashyap,

    Yes, now I will try workflow option.

    I will update status

    Best Regards,

    Kyi Moh

  • Priyesh Profile Picture
    7,396 User Group Leader on at

    Alternatively,

    If you're comfortable using plugins, you can have more detailed logic also included.

    1. Write a plugin on Post-Operation of the Update.

    2. If the desired Stage is being set in the context i.e. the Stage you don't want users to go in, then throw InvalidPluginExecution error and write a message.

    I would recommend this since it will have more comfortable on the restriction if you have added conditions to it.

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 > Customer Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans