Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Prevent you from moving forward in the business process flow

(0) ShareShare
ReportReport
Posted on by 692

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

  • Suggested answer
    Jeet Gandhi Profile Picture
    Jeet Gandhi 320 on at
    RE: Prevent you from moving forward in the business process flow

    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,

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

    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;
    
        }
    }
  • RE: Prevent you from moving forward in the business process flow

    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?

  • Jeet Gandhi Profile Picture
    Jeet Gandhi 320 on at
    RE: Prevent you from moving forward in the business process flow

    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,

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans