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?
@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
@AlexN did you find the resolution for the above problem, I am trying to create something similar.
thanks.