hide forms tab in a form head crm dynamics 365

672 views Asked by At

I have an entity which contains 2 forms, I want to prevent navagation between these 2 forms based on the value of two option field. In other words if the value of need prescoring is yes navigation is not possible and the inverse, how can I do this ?

Is it possible to simply hide the list ?

Thanks,

enter image description here

3

There are 3 answers

0
Arun Vinoth-Precog Tech - MVP On

You can decide based on your project complexity wrt number of form controls/tabs/sections. We did something like this to maintain & forced navigation based on form control value.

    var taskFormOptionSet = {
        Form1: 1,
        Form2: 2,
    };

        var FormNames = {
            Form1: "Form1",
            Form2: "Form2",
        };

    var myform = Xrm.Page.getAttribute("need_Prescoring").getValue();
    var currentform = Xrm.Page.ui.formSelector.getCurrentItem();

    if (currentform != null) {
        var formId = currentform.getId();
        var formLabel = currentform.getLabel();
    }

    if (myform == taskFormOptionSet.Form1 && formLabel != FormNames.Form1) {
        var items = Xrm.Page.ui.formSelector.items.get();
        for (var i in items) {
            var form = items[i];
            var formId = form.getId();
            var formLabel = form.getLabel();

            if (formLabel == FormNames.Form1) {
                form.navigate();
                return;
            }
        }

    }
2
Henrik H On

No, you cannot dynamically change the forms the user can select. This can only be done statically based on security roles.

Instead I suggest using a single form, where you hide and show the relevant fields/sections/tabs based on the value of your Need Processing field.

2
Marwan On

As it's not supported I used another solution which is to check if the boolean is true and the name of the, if the user tries to change the form he will be redirected to the right form until he changes the value of the boolean.

DiligenceSwitch: function(){
    if (Xrm.Page.ui.formSelector.getCurrentItem() != null) {
        var currentform = Xrm.Page.ui.formSelector.getCurrentItem();            
    }

    if (currentform != null) {
        var formId = currentform.getId();
        var formLabel = currentform.getLabel();
    }

    var kycId = Xrm.Page.data.entity.getId();        
    SDK.REST.retrieveRecord(kycId, "kyc_Kycdiligence", "kyc_Needprescoring", null,               //field for searching the targeted field, entity, targeted field, ...
        function (kyc) {
            if (kyc != null || kyc.kyc_Needprescoring != null) {
                if (formLabel != "Pre-Scoring" && kyc.kyc_Needprescoring == true) {     
                    var windowOptions = { openInNewWindow: false };
                    var parameters = {};
                    parameters["formid"] = "4B0C88A9-720C-4BFA-8F59-7C1D5DD84F02";
                    Xrm.Utility.openEntityForm("kyc_kycdiligence", kycId, parameters, windowOptions);
                    alert("Vous devez faire le pre-scoring");    
                }
            }   
        },
        function (error) {
            Xrm.Utility.alertDialog(error.message);
        });
},