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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Prevent a user from going to new stage on a Business Process Flow

(0) ShareShare
ReportReport
Posted on by

Hi, I'm trying to prevent a user to be able to go to the next stage. Let's say I have 4 stages in my BPF. The BPF main entity is an opportunity. The first 3 stages of my BPF are related to the opportunity. The 4th stage is related to a custom entity linked to my opportunity. When I'm on my 3rd stage and want to go to the fourth, I want to validate that all the required fields in my opportunity form are filled to let the user go to my fouth stage which is related to my other custom entity. 

The required fields (which are numerous) that can prevent from being able to go to next stage are in the opportunity form, but not in the BPF stage. 

I tried many ways: 

I made a process workflow (on opportunity, not a background one...) that is executed when the stageid changes. For a reason I ignore, the stageid raises each time I change from stage 1 to 3, but when on 3 and aks for the 4th stage, since I swap entity type and the BPF ribbon ask me to create a new entity, the stageid trigger is not hit.

I tried with javascript with methods "Xrm.Page.data.process.setActiveProcess" and "Xrm.Page.data.process.addOnStageChange", but I am not able to catch the moment when I hit the "Next button" stage and before I land on the next stage to prevent the change of stage.

Do someone have an idea on how I can prevent to move to new stage bases on form fields that are not in the current BPF stage?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Nuno Profile Picture
    2,005 on at

    Hi,

    With OnStageChange you should be able to catch the moment when the button next or previous are clicked. The methog getdirection return 'Next' or 'Previous' depending on the clicked button.

    msdn.microsoft.com/.../d88d5f21-6385-443b-91f2-0ec0c16b1324

    Xrm.Page.data.process.addOnStageChange(onStageChange);

    function onStageChange()

    {

    alert(ExecutionContextObj.getEventArgs().getDirection()) // alerts "next" or "previous"

    }

  • Verified answer
    awalters Profile Picture
    3,079 on at

    This is a bit of a workaround, but I think it might work for you.  (We're considering something similar.)

    Have a read-only flag that is basically "are all required fields completed".  Show and require this flag on the BPF, but hide it on the form.  Have a business rule that sets the value of the flag to yes when all of the required fields are filled in.  Then you don't need each field up on your BPF, but without them filled in, then you can't go onto the next stage because the BPF requires the flag to be yes.

    This has the added advantages of not being in code, so easier maintenance, plus it gives an extra visual reminder to the user.

  • awalters Profile Picture
    3,079 on at

    Here's a page that talks about a similar solution (though it's for a slightly different use case) - www.magnetismsolutions.com/.../making-a-field-read-only-on-a-business-process-flow

    It makes an interesting note about a business rule being needed to make a field read-only on the BPF - haven't tested this yet though.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Frantz,

        I have done this for a number of clients - I created a plugin that fires on the Update pre-operation of the Opportunity entity. The plugin checks for the stageid of the next stage (you can also use the stageid to get the stagename, if that's better for you), and if it matches the value of the next stage, an exception (of type InvalidPluginException) is thrown. Works great!

    Hope that helps,

    John

  • Community Member Profile Picture
    on at

    Hi Allison, thanks for the help. Last week I ended up with a solution that is really close to what you suggested, but instead I used  a calculated field that I flagged as required in the BPF. I'm kind of new to Crm and struggled a little bit on this workaround. First I tried to use a two option (y/n) calculated field, but the field always add a value. Then I used a calculated field that is a single text line that I fill or clear following the conditions I need to meet to let user go on next stage. But a calculated field can only contains ands or ors, and my condition was more complex than what I can do with only ands or ors. I had to split the condition in many if/else/else... conditions. But it finally worked. The other think is that I wanted to hide this calculated field from the BPW. I made it with a business rule, but the thing is that when my required field has a value, the field is hidden but there is a check that appears on the space that the hidden field occupies in the stage form... So my solution works, but I would like a cleaner solution and I will maybe change it to use the solution you suggested... Thanks again

  • awalters Profile Picture
    3,079 on at

    No worries.  :-)  Good luck!

  • Community Member Profile Picture
    on at

    hi Allison  is there any method apart from this why because we want to keep a field(extra) for every stage to restrict which make more fields in bpf

  • MateuszBender Profile Picture
    216 on at

    This doesn't work in CRM 9.X, as the stageid is no longer used!

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans