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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / BPF with multiple enti...
Power Apps
Answered

BPF with multiple entities opening the wrong form

(0) ShareShare
ReportReport
Posted on by 269

Hey,

I have a BPF with multiple entities (first stage is on base entity A, second too, the third one however is connected to entity B).
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?

Categories:
I have the same question (0)
  • dSingh_365_CRMGuy Profile Picture
    4 on at

    @AlexN did you find the resolution for the above problem, I am trying to create something similar. 

    thanks.

  • Verified answer
    AlexN Profile Picture
    269 on at

    @tejsidhu_ozYes, I actually did.
    I did it with Javascript during the formOnLoad using following parts (edited the full code a bit to leave only the important parts:

    const VariantStageNames = [
     'Stage 3',
     'Stage 4',
     'Stage 7'
    ];
    
    this.formOnLoad = function (executionContext) {
     var formContext = executionContext.getFormContext();
     var formType = formContext.ui.getFormType();
     if (formContext.data.process != null && formContext.data.process != undefined) {
     var selectedStage = getSelectedStage(formContext);
     if (selectedStage != null && selectedStage != undefined) {
     var selectedStageName = selectedStage.getName();
     if (VariantStageNames.includes(selectedStageName)) {
     switchToSecondEntity(formContext, selectedStageName);
     }
     }
     }
     }
     }
    
    function switchToSecondEntity(formContext, selectedStageName) {
     let recordId = formContext.data.entity.getId();
    
     // know which is the active BFP stage
     Xrm.WebApi.retrieveMultipleRecords("xxx_yyy_businessprocessflow", `?$select=_activestageid_value,_bpf_xxx_secondentityid_value,statecode&$filter=_bpf_xxx_firstentityid_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]._bpf_xxx_secondentityid_value
     //get the active stage information
     Xrm.WebApi.retrieveRecord("processstage", result.entities[0]._activestageid_value, "?$select=primaryentitytypecode").then(
     function (result) {
     if (result.primaryentitytypecode !== "xxx_firstentity") {
     // 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 () { }
     );
     },
     function () { }
     );
     }

     Not the best code maybe, but it works

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 Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 525 Most Valuable Professional

#2
Haque Profile Picture

Haque 273

#3
Kalathiya Profile Picture

Kalathiya 232 Super User 2026 Season 1

Last 30 days Overall leaderboard