POWEROBJECTS

718 Washington Ave. N. Suite #101
Minneapolis, MN 55401
View map and all Locations

Send us a message

Disclaimer: This blog is for information purposes ONLY and contains unsupported code that is subject to break during major CRM updates.

tips-and-tricks

Microsoft Dynamics CRM 2015 features a new Quick Create form. One of the enhancements that come with the new Quick Create form is that users can now add JavaScript to the form exclusively. In today’s blog, we will delve into the new Quick Create form in more detail and we will also outline the steps needed to add JavaScript to the form. This will help users utilize the new Quick Create form features more effectively. Let’s get started!

Note: Experience with creating JavaScript web resources is helpful in completing this solution.

There are multiple places within CRM where the Quick Create form can be used:

A. The main application ribbon on the top of your window.

Adding JavaScript

B. From the +New button found on the drop-down menu on an entity form.

Adding JavaScript

C. From the + button on sub-grids (and associated views when adding a new item).

Adding JavaScript

In this post, we will be focusing on certain parameters that are available for item B as described above. This is generally helpful when you have specific JavaScript to run against specific look-ups on entity forms. In this example, we want to set a specific field on the contact record depending on which +New button is clicked on the Case form. We can do this on the Quick Create form’s on-load event and use some parameters that are available from the parent window calling the Quick Create form. There are two parameters that are available on the Quick Create form when called from a look-up control (CreateFromId and CreateFromType) that will determine which entity/record it is being called from. These are available as part of the Xrm.Page.context.getQueryStringParameters() from the Quick Create form onload.

Below is the sample code for setting the ParentCustomerId and Customertypecode fields on the Quick Create contact form when the +New button is clicked:

function Form_Onload() {

var contextParams = Xrm.Page.context.getQueryStringParameters();

 

if (contextParams._CreateFromType != null && contextParams._CreateFromType == 112) {

var contactLookup = top.document.getElementById(‘new_contact_i_lookup_quickcreate’);

var customerLookup = top.document.getElementById(‘customerid_i_lookup_quickcreate’);

var contentFrame = top.document.getElementById(‘contentIFrame0’);

 

if (contentFrame != null) {

 

var clientLookup = contentFrame.contentWindow.Xrm.Page.getAttribute(“new_account”);

if (clientLookup != null) {

var clientValue = clientLookup.getValue();

if (clientValue != null) {

Xrm.Page.getAttribute(“parentcustomerid”).setValue(clientValue);

}

}

if (customerLookup != null) {

Xrm.Page.getAttribute(“customertypecode”).setValue(100000000); //Customer

}

if (contactLookup != null) {

Xrm.Page.getAttribute(“customertypecode”).setValue(100000001); //Contact

}

}

}

}

After you use the code above on the Quick Create form of contact, try creating a new contact from the Case’s customerid look-up. This will set the new_account (Account look-up) from the case form to the ParentCustomerId (Parent Customer) field on the Quick Create form. You will also want to set the Customertypecode (relationship type) field on the contact create form to Customer as shown in the steps below:

1. Once an Account is selected, the customer look-up +New button is clicked.

Adding JavaScript

2. Next, the Quick Create form opens with the Parent Customer set to Blue Yonder Airlines (sample) and Relationship Type set to Customer.

Adding JavaScript

3. Similarly, when the Contact look-up +New button is clicked, the Customer Name and Relationship Type (=contact) are populated accordingly.

Adding JavaScript

Adding JavaScript

To explain the code, this if statement determines that the quick create contact form is being called from the case form: if (contextParams._CreateFromType != null && contextParams._CreateFromType == 112)

The two lines of code below will get the contact look-ups that are initiating the Quick Create form within the case form itself:

var contactLookup = top.document.getElementById(‘new_contact_i_lookup_quickcreate’);

var customerLookup = top.document.getElementById(‘customerid_i_lookup_quickcreate’);

Note: This particular code is accessing the DOM and hence is un-supported. However, it will do the trick in CRM 2015! The first part of the element name is the CRM field name, but this might be different if the field is added twice in the form. CRM tends to create the name as new_contact1 (for the new_contact field) if it is added twice on the form.

Based on whichever element is available, you can set the Relationship Type on the opened Quick Create form.

Finally, use this last piece of code to set the Parent Customer depending on the Case form’s Account field value:

var clientLookup = contentFrame.contentWindow.Xrm.Page.getAttribute(“new_account”);

if (clientLookup != null) {

var clientValue = clientLookup.getValue();

if (clientValue != null) {

Xrm.Page.getAttribute(“parentcustomerid”).setValue(clientValue);

}

}

This is more straight-forward in that we are getting it from the main content frame window which has the XRM object and can get any field values from the form itself.

We hope you found today’s blog helpful! These little tricks will come handy in various situations in terms of utilizing the new Quick Create forms more productively. To keep up to date on more tips and tricks like this one, be sure to subscribe to our blog!

Until next time, happy CRM’ing!

Avatar for JoeCRM

JoeCRM

Joe CRM is a CRM superhero who runs on pure Microsoft Dynamics CRM adrenaline. As the face of PowerObjects, Joe CRM’s mission is to reveal innovative ways to use Dynamics CRM and bring the application to more businesses and organizations around the world.