Change form in CRM 365

Sometimes, we want to dynamically change our default form based on specific requirements. In this time, I’ll show how can we achieve this by setting a Form based on its name. Javascript Code below:

            // Form(Name) that we're trying to set
            var Target_Form = "MY FORM";

            if (Xrm.Page.ui.formSelector.getCurrentItem() != null)
                // Get current Form Name
                var Current_Form = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

                // If current Form is not the form we're looking for, then...
                if (Current_Form != Target_Form)
                    // Get all Entity Forms
                    var EntityForms = Xrm.Page.ui.formSelector.items.get();

                    // Iterate on all Forms of the Entity
                    for (var i in EntityForms)
                        // Get Form Item
                        var FormItem = EntityForms[i];

                        // If Form Item is not null, then...
                        if (FormItem != null) {

                            // Get Form ID and Name
                            var Form_Id = FormItem.getId();
                            var Form_Name = FormItem.getLabel()

                            // If Form Name equals Target Form, then...
                            if (Form_Name == Target_Form)

                                // Navigate to the Form

Hope it helps.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s