Opening a Quick Create through JavaScript

Leave a comment

In Dynamics 365, we can open Quick Create forms through JavaScript.

Through Xrm.Utility, we can call openQuickCreate. This takes the parameters:

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

From the documentation, we can see the parameters required:

Name Type Required Description
entityLogicalName String Yes The logical name of the entity to create.
createFromEntity Lookup No Designates a record that will provide default values based on mapped attribute values.

A lookup object has the following String properties:

  • entityType: the logical name of the entity.
  • id: A string representation of a GUID value for the record.
  • name: The primary attribute value of the record.
parameters Object No A dictionary object that passes extra query string parameters to the form. Invalid query string parameters will cause an error.

Valid extra query string parameters are:

  • Default Field Ids, To set default values for a new record form.
  • Custom query string parameters, A form can be configured to accept custom query string parameters.
successCallback Function No The function that will be called when a record is created. This function is passed an object as a parameter. This object has a savedEntityReference property with the following properties to identify the record created:

  • entityType: the logical name of the entity.
  • id: A string representation of a GUID value for the record.
  • name: The primary attribute value of the record created.
errorCallback Function No A function to call when the operation fails.

An object with the following properties will be passed:

  • errorCode, Number. The error code.
  • message, String. A localized error message.

In the first example, let’s say when creating an Account, we would like to create a child account through Quick Create after we tab off the Account field.

Create a new web resource to hold our JavaScript code:

In our code, we will set the name of the child account to “Child account of ” and then get the name of the account entered on the page:

function OpenQC() {

 var thisAccount = {
    entityType: "account",
    id: Xrm.Page.data.entity.getId()
 };
 var callback = function (obj) {
    console.log("Created new " + obj.savedEntityReference.entityType + " named '" + obj.savedEntityReference.name + "' with id:" + 
 obj.savedEntityReference.id);
 }
 var setName = { name: "Child account of " + Xrm.Page.getAttribute("name").getValue() }; 
 Xrm.Utility.openQuickCreate("account", thisAccount, setName).then(callback, function (error) {
    console.log(error.message);
 });

 }

Attach the code to the Account field:

Now create a new account. After typing the name, the Quick Create will open:

Now let’s say we want to open the Contact Quick Create instead. We can change the code to set the parameters of the first name of the contact:

function OpenQC() {
 var thisAccount = {
    entityType: "account",
    id: Xrm.Page.data.entity.getId()
 };
 var callback = function (obj) {
    console.log("Created new " + obj.savedEntityReference.entityType + " named '" + obj.savedEntityReference.name + "' with id:" + 
 obj.savedEntityReference.id);
 }
 var setName = { firstname: "Contact Name for " + Xrm.Page.getAttribute("name").getValue() }; 
 Xrm.Utility.openQuickCreate("contact", thisAccount, setName).then(callback, function (error) {
    console.log(error.message);
 });

 }

Now entering an account brings up the contact quick create form:

 

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

5 + 13 =