Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Automatically set BPF active stage based on case status reason

Posted on by 594

Hi CRM World,

I am facing an issue with BPF. We have 3 status reasons: Progress, pending and resolved and we have 3 BPF stages respectively. I am writing java script on form load event so that based on the status reason i need to automatically change to respective BPF stage. 

1. movenext() and moveprevious() works fine only when case is active. If case is resolved my java scripts throws an error. How to overcome this issue for resolved case. Tried using WebAPI calls inside java script, but still failed.

2. If i want to directly move from 1st BPF stage to 3rd BPF stage i am moving 2 movenext() consecutive statements. But only one of them is working (and to my surprise first statement returns invalid and next statement works fine). Is there any other way to achieve this?

Thanks in advance 

*This post is locked for comments

  • Verified answer
    chakkay Profile Picture
    chakkay 594 on at
    RE: Automatically set BPF active stage based on case status reason

    Thanks Goutam for quick reply.But you script wont work in my case as when case is resolved the form becomes read only. When i try to update BPF stage it failed.

    Workaround:

    From Dynamics 365 8.2, we have a new feature where a new entity (with same name as BPF) is created for every BPF rule in CRM. If a case record is created, new record in the BPF entity will be created.

    I have written OOB workflow and made changes to the associated BPF record. This will reflect my stage change in case record. (FYI since case is parent and associated BPF is child record we can create a lookup field on case form to point to associated BPF record thus accessing the related BPF record from case entity through lookup)

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Automatically set BPF active stage based on case status reason

    Hi ,

    Try to call below code in the onload function.

    function OnloadFormData()
    { 
    Xrm.Page.data.process.addOnStageSelected(checkSelectedStagechange);
    }
    


  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Automatically set BPF active stage based on case status reason

    Hi , 

    May be you need to write the logic as per your requirement but below code may help you -

    Its basically automatically click to next stage ,if the current stage and selected stage id is not same.

            Xrm.Page.data.process.addOnStageSelected(checkSelectedStagechange);
    
            function checkSelectedStagechange() {
                var currentStageId = Xrm.Page.data.process.getActiveStage().getId(); //You need to write your logic here
                var selectedStageId = Xrm.Page.data.process.getSelectedStage().getId();
                if (currentStageId != selectedStageId) {
                    Xrm.Page.data.process.setActiveStage(currentStageId, MoveNextStageBPF)  //Move next stage 
                }
            }
    
            function MoveNextStageBPF() {
                var activeStage = document.querySelector(".processStageContainer.activeStage");
                if (activeStage)
                    activeStage.click()
            }


    Hope this helps.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans