Skip to main content

Notifications

Power Apps - Building 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?

  • Verified answer
    AlexN Profile Picture
    AlexN 269 on at
    Re: BPF with multiple entities opening the wrong form

    @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

  • Re: BPF with multiple entities opening the wrong form

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

    thanks.

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,343

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,703

Leaderboard