Search code examples
dynamics-crmcrm

Create new record depending option set field value


I have custom entity with a few required fields. One of them is the record type field, that can have value internal, external type 1, external type 2. There is also a lot of Subgrids and fields and each of them is visible just for one of record type values.

Is there a way to make a few forms for one entity, with some basic form containing just the record type field, that would redirect me to the selected form depending on selected record type. That form would have just the components required by the record type. And if there is a way to do that, is it the best practice, or it would be better to keep everything on the same form and set visibility using JavaScript?


Solution

  • Depends on the form complexity. If there is a not a lot happening on the form, show/hide tabs would be the best option. But if there are a lot of fields and a lot of logic it is better to use different forms and use form selector's Navigate property to force the users to a different form based on the selection. Keeps things much cleaner.

    If the form has unsaved values you might also either have to do a Save and navigate.

    function recordType_OnChange() {
        Xrm.Page.data.save().then(function() {
            Xrm.Page.ui.formSelector.items.get(formId).navigate(); //switch formId based on record type value
        }, function(error) {
            console.log(error);
        });
    }