Alternative to showModalDialog

By | September 17, 2014

Recent update to Chrome is such a hurtful update for CRM developers. It broke many of the CRM functionalities. It deprecated our favorite showModalDialog method.

Due to the deprecation of showModalDialog method, we faced many issues. Out of those, we are going to talk about the CRM Lookup Dialog, that we used to get using showModalDialog. Since the showModalDialog is deprecated, how to get the CRM Lookup Dialog now? We cant get the CRM Lookup Dialog again? How difficult would be to create the custom Lookup Dialog? hush...

These are the questions haunting most of the developers. Let us help you out on this issue.

Yeah! It's still possible to get the CRM Lookup using script. But, instead of showModalDialog, we would be using another CRM method to get the Lookup.

Lets Look into it, previously we used to use showModalDialog method, now, we`ll use Xrm.Internal.openDialog method. Below code will explain you how to achieve it.

Code:

function OpenLookup() {

//set entity choice

var objectCode = “1084”;

 

//prepare lookup url

var url = “/_controls/lookup/lookupsingle.aspx?objecttypes=” + objectCode;

 

//Dialog Options would be set here

var DialogOptions = new Xrm.DialogOptions();

DialogOptions.width = 500;

DialogOptions.height = 400;

 

//open dialog

Xrm.Internal.openDialog(Mscrm.CrmUri.create(url).toString(), DialogOptions, null, null, CallbackFunction);

}

//Call back function for the Lookup

function CallbackFunction(returnValue) {

if (isValid(returnValue) && isValid(returnValue.items) && isValid(returnValue.items[0].id) && isValid(returnValue.items[0].name)) {

//Set the Name in the textbox

$(“#quoteId”).val(returnValue.items[0].name);

//Set the Id on the extra attribute called attr

var guid = returnValue.items[0].id;

$(“#quoteId”).attr(“guid”, guid);

}

}

 

For this demo we are using an HTML webresource, on the HTML webresource we have a textbox and a Lookup button. On the click of the Lookup button, openLookup function is triggered. Callback function is where we are getting the selected record details. In the textbox we are setting the name and we have added an extra attribute called “guid” on the textbox field itself to store GUID of the record.

Below is the actual screenshot of the demo:

1

Wow, this simple it is now to get the Lookup Window Dialog. And, the best part, it is exactly like the OOB Lookup window.

A part of the solution was suggested on this thread by Rami Heleg.

Note: Use of Xrm.Internal is unsupported as per SDK.

Thanks

Category: Dynamics CRM 2013 Tags: , ,

About Inogic

Inogic is one of the most renowned Microsoft ISV with a Gold competency in Microsoft Dynamics CRM ecosystem. Inogic is a hub of innovation, and cutting-edge technologies delivering innovative services and solutions like Maplytics™, one of the first geo-analytical mapping solutions to be Certified for Microsoft Dynamics (CfMD) & InoLink: QuickBooks Integration, to CRM Customers and Partners alike.

Leave a Reply