Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Prevent business process flow from moving forward

Posted on by 690
good afternoon everyone,

Within the Opportunity screen I have three bits fields that when the user clicks phase advance in the Business Process Flow, it checks and if the fields are not filled, it does not let the user advance in the business process flow, however I have to do this via javascript

It's possible?

*This post is locked for comments

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Prevent business process flow from moving forward

    Hi Ricardo,

    I have added one condition , let say I am getting the value from checkbox that whether its checked or not . If its not checked then we can not move the BPF next stage , thats why you can see next line I am setting current stage and click on the current stage on call back method.

    function OnloadBPF()
    {
        Xrm.Page.data.process.addOnStageSelected(checkSelectedStagechange);
    }
    function checkSelectedStagechange() {
        var currentStageId = Xrm.Page.data.process.getActiveStage().getId();
        var selectedStageId = Xrm.Page.data.process.getSelectedStage().getId();
    
     
        var myControl = Xrm.Page.ui.controls.get("checkboxattributename");
        var myCheckboxValue = myControl.getAttribute().getValue();
        if (myCheckboxValue == false) {   // Get the value from  checkbox is true or not , you can add multiple condition here .
    
            if (currentStageId != selectedStageId) {
                Xrm.Page.data.process.setActiveStage(currentStageId, callbackFunction);
            }
    
        }   
        
    }
    
    function callbackFunction() {
        var activeStage = document.querySelector(".processStageContainer.activeStage"); // Please note this is unsupported
        if (activeStage)
            activeStage.click()
    }
    


  • RE: Prevent business process flow from moving forward

    Hello outam Das,

    Thanks for the feedback.

    I do not think I explained my case correctly, I apologize, I'll try to illustrate better.

    I have an Opportunity, where I have a section with several checkbox fields.

    I need that when the user tries to advance to the next phase, if none of these check boxes is checked, the user can not move forward, ie it is blocked to move to the next phase via Javascript.

    In your code you put the line:

    if (Check fill data)

    I did not understand this line and I also did not understand where the line would be that blocks his advance to the next phase ...

    Would this event be in the correct OnSave?

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Prevent business process flow from moving forward

    Hi Ricardo , 

    My apologies ! I have not understand correctly earlier your questions now I am understood.  I have updated the code in my earlier post , you need to add additional if condition to check the  mandatory field has filled up or not .

    function OnloadBPF()
    {
       Xrm.Page.data.process.addOnStageSelected(checkSelectedStagechange);
    }
    function checkSelectedStagechange() {
        var currentStageId = Xrm.Page.data.process.getActiveStage().getId();
        var selectedStageId = Xrm.Page.data.process.getSelectedStage().getId();
    if( Check fill Data )
    {
    if (currentStageId != selectedStageId) { Xrm.Page.data.process.setActiveStage(currentStageId, callbackFunction) }
    } } function callbackFunction() { var activeStage = document.querySelector(".processStageContainer.activeStage"); // Please note this is unsupported if (activeStage) activeStage.click() }


  • RE: Prevent business process flow from moving forward

    Hello Gutam Das,

    I have some doubts, this javascript will run on OnSave, I ask why I need to perform the same command as I step forward.

    And what is the line that keeps you from saving?

    Thank you

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Prevent business process flow from moving forward

    Hi Ricardo,

    You can try with this - 

    function OnloadBPF()
    {
       Xrm.Page.data.process.addOnStageSelected(checkSelectedStagechange);
    }
    function checkSelectedStagechange() {
        var currentStageId = Xrm.Page.data.process.getActiveStage().getId();
        var selectedStageId = Xrm.Page.data.process.getSelectedStage().getId();
        if (currentStageId != selectedStageId) {
            Xrm.Page.data.process.setActiveStage(currentStageId, callbackFunction)
        }
    }
    
    function callbackFunction() {
        var activeStage = document.querySelector(".processStageContainer.activeStage"); // Please note this is unsupported
        if (activeStage)
            activeStage.click()
    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans