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 :
Microsoft Dynamics CRM (Archived)

Prevent you from moving forward in the business process flow

(0) ShareShare
ReportReport
Posted on by 694

Good afternoon everyone,

Within my Opportunity I have a Competitor grid that needs to have at least one Competitor linked to Opportunity.

And I also have the Business Process flow, I need that if you do not have at least one Competitor linked to the Opportunity, you can not advance to the next stage in the Business Process Flow.

Is this possible? I need to do this via Java Script

Tank You

*This post is locked for comments

I have the same question (0)
  • Jeet Gandhi Profile Picture
    320 on at

    Hi,

    Yes it is possible. It can be in the way like on change of the field "stageid" Javascript code can be executed that retrieves the related Competitors entities. If the count of the retrieved entities is 0 then prevent the record from getting saved.

    To retrieve related records, there are several options:

    1.. FetchXml

    2.  Web API call

    To prevent the record from saving, please refer below link:

    neilparkhurst.com/.../javascript-prevent-save

    I hope it would be helpful.

    Please mark the answer if helpful

    Thank you,

  • Ricardo Rodrigues dos Santos Profile Picture
    694 on at

    Hello thanks for the reply

    The part of retrieving related records via FehtchXml and API I can do a retrieve and verify, however the hardest part is to prevent the business process flow coming forward and if I am not mistaken the function:

    1 .. FetchXml

    2. Web API call

    function onSave (context) {

       var saveEvent = context.getEventArgs ();

       if (Xrm.Page.getAttribute ("telephone1"). getValue () == null) {

         // *** Note: I'm using an alert to test a notification maybe better!

         alert ("Put in a phone number!");

         saveEvent.preventDefault ();

       }

    }

    And for the form and not the right business process flow?

    Could you tell me the shape of the business process flow?

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Ricardo ,

    Try with this - 

    //Register below method in on load 
    function StageChangeOnload() {
        Xrm.Page.data.process.addOnStageChange(checkSelectedStage);
    }
    
    function checkSelectedStage() {
        var result = true;
        var stageName = Xrm.Page.data.process.getSelectedStage().getName().toString().toLowerCase();
        var stageID = Xrm.Page.data.process.getSelectedStage().getId();
        if (stageName == "Advance") {
            Xrm.WebApi.retrieveMultipleRecords("account", "?$select=name&$top=3").then( // Add filter criteria as per requirement
            function success(result) {
                if (result.entities.length > o) {
                    Xrm.Page.ui.clearFormNotification("2001");
                    result = true;
                }
                else {
                    Xrm.Page.ui.setFormNotification("Please add at least one competitor", "INFO", "2001");
                    result = false;
                    return;
                }
    
            },
            function (error) {
                result = false;
                console.log(error.message);
            }
       );
    
            return result;
    
        }
    }
  • Suggested answer
    Jeet Gandhi Profile Picture
    320 on at

    Hi,

    For that, I think you can implement the same logic on save of the form. Like on save you validate if "stageid" is dirty or not. If it's dirty, then retrieve the related competitors and validate the count.

    If the count is 0, prevent the record from saving using the above code.

    Note, if you prevent the code from saving, the stage of the BPF will not get updated.

    Please mark the answer if helpful.

    Thank you,

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans