Showing posts with label openQuickCreate. Show all posts
Showing posts with label openQuickCreate. Show all posts

Wednesday, October 26, 2016

Xrm.Utility functions : openQuickCreate

There is another good function in Xrm.Utility object : openQuickCreate. This function is only available for CRM 2015 (update 1) online or later versions.
Using this function we can open quick create form for entity even there is not any direct relationship.
e.g. if you have any custom entity, and this custom entity is not has any relationship with contact but for some reason when this custom entity form opens, you want to create contact / want to open contact quick create, you can use this Xrm.Utility function.
With openQuickCreate function, you can set default values on form by passing parameters and/or by using query string parameters and/or using attribute mapping defined in relationship.
Common syntax for openQuickCreate is

Xrm.Utility.openQuickCreate(entityLogicalName,createFromEntity,parameters).then(successCallback, errorCallback);

To open any entity quick create form only entityLogicalName is required, other parameters are optional.

When wants to open just quick create form without setting any default values, then we can use

Xrm.Utility.openQuickCreate( "contact",);

This will open quick create form for contact entity.

For all details about parameters, please check

The complete example of openQuickCreateForm is

carScript = {

        var thisEntityRecord = {
            entityType: "new_car",
            name: Xrm.Page.getAttribute('new_name').getValue()
        var parameters = {};
        parameters["new_manufactureaddress"] = Xrm.Page.getAttribute('new_manufactureaddress').getValue(); 
        Xrm.Utility.openQuickCreate("new_manufacture", thisEntityRecord, parameters).then(carScript.setManfactureLookup,carScript.errorfun);

        var lookup = new Array();

This function is called on form load; once form is loaded, quick create form for Manufacture (custom entity) will be displayed.  Once quick create record is saved, setManfactureLookup is called, which will set Manufacture lookup in car entity.
 When quick create record saved, you will get saved record entity reference object in SuccessCallbackfunction.

Note: There is a limit of 10 nested quick create forms in the web application. If this limit is exceeded this function will open the full entity form rather than quick create form.