|
function setOpportunityFormType(executionContext) {
var formContext = executionContext.getFormContext(); //Determine Form currently loaded. If null returned, it means only one form is available. Just exit. //SRC: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/formContext-ui-formSelector var selectedFormReference = formContext.ui.formSelector.getCurrentItem();
if (!selectedFormReference) { console.log("setOpportunityFormType: No additional forms are available for switching."); return; } console.log("setOpportunityFormType:SelectedForm:" + selectedFormReference.getLabel()); //Get Business Unit Value
var BUvalue = formContext.getAttribute("owningbusinessunit").getValue(); if (!BUvalue) { console.log("setOpportunityFormType: Business Unit field missing or null."); return; } console.log("setOpportunityFormType:BUvalue:" + BUvalue); //Define the form dictionary mapping Business Unit values to the appropriate form guid.
formDict = { "8841ae65-bb3d-ee11-bdf4-000d3ab69899": "1a89ad94-4210-ee11-8f6d-0022489fdf9a", "72a22850-0eef-ed11-8848-0022489fdf9a": "1a89ad94-4210-ee11-8f6d-0022489fdf9a", "87c1ee29-0eef-ed11-8848-0022489fdf9a": "1a89ad94-4210-ee11-8f6d-0022489fdf9a", "2137a55f-bb3d-ee11-bdf4-000d3ab69899": "595978a6-704c-4aec-aab8-34f3927c1cda", "5b4644d6-0def-ed11-8848-0022489fdf9a": "595978a6-704c-4aec-aab8-34f3927c1cda", "02a26dfb-0def-ed11-8848-0022489fdf9a": "595978a6-704c-4aec-aab8-34f3927c1cda", "cac2b40f-0eef-ed11-8848-0022489fdf9a": "595978a6-704c-4aec-aab8-34f3927c1cda", "dd9ba66b-bb3d-ee11-bdf4-000d3ab69899": "e277e15f-088e-ee11-8179-000d3ab76a71", "d389397c-a23d-ee11-bdf4-000d3ab69899": "e277e15f-088e-ee11-8179-000d3ab76a71", "5921c6c4-a23d-ee11-bdf4-000d3ab69899": "e277e15f-088e-ee11-8179-000d3ab76a71" }; // Determine if Selected Form is correct, and if not, load the correct form.
var selectedFormId = selectedFormReference.getId(); if (selectedFormId === formDict[BUvalue]) { console.log("setOpportunityFormType:Correct Form Already Loaded."); } else if (selectedFormId !== formDict[BUvalue]) { var targetForm = formContext.ui.formSelector.items.get(formDict[BUvalue]); // if TartForm available in formSet attempt to navigate to it. if (targetForm === null) { //alert("setOpportunityFormType: Automatic form selector unable to load correct form for this Business Unit. Please report this to the IT Support Team. TargetForm for this Business Unit is not available. Some fields and system features may not be available if using the current form."); var alertStrings = { confirmButtonLabel: "I understand.", text: "Unable to load correct form for this Business Unit. Some fields and system features may not be available. Please report this to the IT Support Team." }; var alertOptions = { height: 250, width: 300 }; Xrm.Navigation.openAlertDialog(alertStrings, alertOptions); } else { //If form is dirty, save then navigate. if (formContext.data.entity.getIsDirty()) { console.log("setOpportunityFormType:Incorrect Form Loaded. Fields dirty. Saving and Switching Forms."); formContext.data.save().then(function () { targetForm.navigate(); }); } //If Clean, just navigate. else { console.log("setOpportunityFormType:Incorrect Form Loaded. Fields clean. Switching Forms."); targetForm.navigate(); }
} } else { console.log("setOpportunityFormType:Error determining if correct form is loaded."); } } |


Report
All responses (
Answers (