Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

Dynamically switching forms causing issues

$
0
0

I have several forms on the same entity.

I need to switch forms when form loads, depending on a field's value.

For a specific form this works great, for the rest of the forms though, although the switching happens and the correct form loads, this is causing issues such as to not be able to Save And Close neither to click on the Back button.

I am guessing that this is a loop issue, although I can not figure out why.

I've figured out that on pressing these buttons (Back Button and Save And Close Button) the onload event fires again.

It seems that at this time, some other form is detected and the code tries again to navigate to the correct form (although on the UI I see the correct form all the time).

Here is my code:

function changeDeclarationForm(exeContext) {
    var formContext = exeContext.getFormContext();
    if (formContext.ui.getFormType() !== 1) {
        var interestCategory = formContext.getAttribute("doi_interestcategory").getValue();
        var entityID = formContext.data.entity.getId().replace("{", "").replace("}", "");
        var entityName = formContext.data.entity.getEntityName();

        var formID;
        switch (interestCategory) {
            case 100000000:
                formID = "12659A78-75F0-4DBC-A3F5-A209B7C321BA"
                break;
            case 100000001:
                formID = "12659A78-75F0-4DBC-A3F5-A209B7C321BA"
                break;
            case 100000002:
                formID = "12659A78-75F0-4DBC-A3F5-A209B7C321BA"
                break;
            case 100000003:
                formID = "12659A78-75F0-4DBC-A3F5-A209B7C321BA"
                break;
            case 100000004:
                formID = "A93F352F-3C82-4EED-8AC2-124D05B702CF"
                break;
            case 100000005:
                formID = "6E840CF2-970E-4C91-BE55-F485964649C6"
                break;
            case 100000006:
                formID = "50D23B14-4805-4B02-A429-604F3929EA13"
                break;
            case 100000007:
                formID = "64050F37-333B-4745-BD95-34EA9D16A29D"
                break;
            default:
        }

        var pageInput = {
            pageType: "entityrecord",
            entityName: "doi_declarationline",
            formId: formID,
            entityId: entityID
        };

        console.log("isDifferent ", formContext.ui.formSelector.getCurrentItem().getId().toUpperCase() !== formID);
        console.log("FORMID ", formID, "  CurrentForm ", formContext.ui.formSelector.getCurrentItem().getId().toUpperCase());

//works fine onload. On press of the back button or save&close it fires again and logs incorrect form

        if ((formContext.ui.formSelector.getCurrentItem().getId().toUpperCase() !== formID)) {
            Xrm.Navigation.navigateTo(pageInput).then( 
                function success(result) {
                    console.log("success", result);
                },
                function error() { console.log("error") }
            );
        }
    }
}

Thank you


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images