Skip to main content

Notifications

Community site session details

Community site session details

Session Id : SxAOCqrjA93PCveX8fsIFV
Power Apps - Microsoft Dataverse
Unanswered

BPF with multiple entities opening the wrong form

Like (0) ShareShare
ReportReport
Posted on 16 Jun 2023 13:00:10 by 269

Hey,

I have a BPF with multiple entities (first stage is on base entity A (="Planungsgebinde"), second too, the third one however is connected to entity B (="Produktionsvariante")).
B has a relation to A via a lookup field.


Everything is working fine, whenever I create an entity A and switch to stage 3, it's asking me to create or select an entity B.

 

However, when the BPF is already in stage 3 and I open entity A from a list, the BPF is switching to stage 3 like it should, but the form remains on entity A.

It's not opening the correct form of entity B.

I always have to manually click again on stage 3 and only then the BPF seems to understand it's on the wrong form for this step and reloads the page to open entity B's form.

 

This can't be wanted behaviour. And unfortunately I currently don't see a way to fix this by using Javascript.

Anyone had the same setup maybe and had the same problem?

 

Tried to show you the problem in the video attached

  • Luis Arellano Profile Picture
    247 on 17 Jun 2023 at 05:24:09
    Re: BPF with multiple entities opening the wrong form

    No problem, let me know if that works as you expected or if you run into any issues.

  • AlexN Profile Picture
    269 on 17 Jun 2023 at 05:17:27
    Re: BPF with multiple entities opening the wrong form

    Thanks @LuisArellano , that's definitely giving me a good way to start.

     

    I already have code inplace to handle some other things for the current selected/active stage (mostly visibility of tabs and sections) so I already have the code to execute "your" code only in the needed stages.

     

    I already thought of a similar way to get the needed record from the current process, but your code will give me a very good start. (6 years Power Platform, but this is now my first major model-driven app 😂)

  • CU03121049-0 Profile Picture
    15 on 17 Jun 2023 at 05:14:24
    Re: BPF with multiple entities opening the wrong form

    .

  • Luis Arellano Profile Picture
    247 on 17 Jun 2023 at 00:30:29
    Re: BPF with multiple entities opening the wrong form

    @AlexN you can try adding this function in the on_load event of the "Planungsgebinde" form.

     

    Things to check/replace:

    prefix_planungsgebinde - schema name for "Planungsgebinde" table

    oneflowgesamtprozess - with the actualname of your BPF created table. For example for BPF "Lead To Opportunity Sales Process" the name is "leadtoopportunitysalesprocess"
    _planungsgebinde_value -  with the correctschema name. Remember that if your schema name is prefix_planungsgebinde, then here you have to use _prefix_planungsgebinde_value
    _produktionsvariante_value -  with the shcema name for your table b record.

     

     

     

    function on_load(executionContext) {
        let formContext = executionContext.getFormContext();
        let recordId = formContext.data.entity.getId();
     
        // know which is the active BFP stage
        Xrm.WebApi.retrieveMultipleRecords("oneflowgesamtprozess", `?$select=_activestageid_value,_produktionsvariante_value,statecode&$filter=_planungsgebinde_value eq ${recordId}`).then(
            function (result) {
                if ( result.entities.length < 1)
                    return;

                // BPF is completed, do not redirect
                if ( result.entities[0].statecode === 1 )
                    return;
                let activeStageRecordId = result.entities[0]._produktionsvariante_value
                //get the active stage information
                Xrm.WebApi.retrieveRecord("processstage", result.entities[0]._activestageid_value, "?$select=primaryentitytypecode").then(
                    function(result) {
                        if ( result.primaryentitytypecode !== "prefix_planungsgebinde") {
                            // navigate to the linked record which is linked to the BPF active stage
                            var activeStageFormOptions = {};
                            activeStageFormOptions["entityName"] = result.primaryentitytypecode;
                            activeStageFormOptions["entityId"] = activeStageRecordId;
                            Xrm.Navigation.openForm(activeStageFormOptions);
                            return;
                        }
                    },
                    function (e) {console.log(e);}
                );
            },
            function (e) {console.log(e);}
        );
    }
     
    Please note that this code will not work in all cases and it was written specifically for the scenario you described. It has no error handling, etc. But this could get you started if you need it to work as you describe.
     
    Also, Planungsgebinde record won't be visible again until its BPF is completed because it will always be redirected to the active stage in "Produktionsvariante" and this could cause some other issues.
     
     
  • Luis Arellano Profile Picture
    247 on 16 Jun 2023 at 23:33:26
    Re: BPF with multiple entities opening the wrong form

    Hello,

     

    I think that is the correct/expected behavior. When you click on your base entity A, you are requesting the system to see/open that record. Even if that is part of an active BPF process, the system will show you the record you requested but it informs you that this record is in an active BPF showing the active stage.

     

    What have you tried with JavaScript?

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,679 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard

Featured topics

Loading started