Skip to main content

Dynamics – Disable Global Quick Create – JavaScript

Quick create forms can be a little tricky in Model-Driven Apps. Sometimes you want the user to be able to create records using the quick create, from a subgrid on a related form but you don’t want them using the global quick create + button as no lookups will be auto-populated which can lead to javascript logic failing or unassociated records.

Below is a reusable JS snippet I used to disable quick create forms from being launched from the global button. It checks to see if any lookups are populated if not the form is closed and the user is shown a message. Make sure your lookup fields are on the form and can be hidden.

//Sample onload function 
//To be registered on load of the contacts quick create
ContactsOnload = function(executionContext)
{
    //Call the validation function, returns true if one of the related lookups are populated
    if (GlobalQuickCreateValidation(executionContext,"Contacts"))
    {
        //Do other onload stuff,if validation passed, meaning we arent launching from global
    }
};

GlobalQuickCreateValidation = function (executionContext, entityName) {
    var formContext = executionContext.getFormContext();
    var passed = false;
    //check all attributes on the form for populated lookups, ignoring the owner field
    formContext.getAttribute().forEach(function (attribute) {
        if (attribute.getName() !== "ownerid" && attribute.getValue() !== null) {
            if (attribute.getValue()[0]) {
                passed = true;
            }
        }
    });
    if (!passed) {
        //if no lookups were populated show the user a message and close the QC form
        var message = "You cannot create " + entityName + " from the global quick create. Please go to the appropriate parent record and create it from there.";
        Xrm.Navigation.openAlertDialog({ confirmButtonLabel: "OK", text: message }, { height: 170, width: 620 });
        formContext.ui.close();
        return false;
    }
    return true;
};

Creating a contact from the Global quick create will be blocked, but creation from an account subgrid will work fine due to the account lookup being populated.

Charles Osei

Dynamics 365 Consultant @ Hitachi MCSE Business Applications Computer Science – University of Lincoln 2017 Nottingham D365/CRM user group Chapter Leader TDG – Community leader Twitter @charlied3v LinedIn https://www.linkedin.com/in/charlesosei/

Leave a Reply