4

MS CRM 2013 introduced new approach to dialogs opened inside the system. In version 2011 look-ups were opened as separate (modal) windows, but in 2013 look-ups are opened as inline iframes on current page.

Definitely it's possible via following jQuery statements:

$('body').append("<div id='InlineDialog_Background' class='ms-crm-InlineDialogBackground' tabindex='0' style='position: absolute; width: 100%; height: 100%; top: 0px; background-color: rgb(128, 128, 128); z-index: 1005; opacity: 0.5;'></div>");
$('body').append("<div id='InlineDialog' class='ms-crm-DialogChrome' tabindex='1' style='position: absolute; top: 50%; left: 50%; z-index: 1006; margin-top: -240px; margin-left: -400px; height: 540px; width: 800px;'><iframe id='InlineDialog_Iframe' name='InlineDialog_Iframe' src='custom_url' style='height: 540px; width: 800px; border: 0px;'></iframe><div id='DialogLoadingDiv' style='position: absolute; background-color: white; height: 480px; width: 800px; top: 50%; left: 50%; margin-top: -240px; margin-left: -400px; z-index: 1007; display: none;'><table class='ms-crm-LoadingContainer' style='width:100%;height:100%'><tbody><tr class='ms-crm-LoadingContainer'><td style='vertical-align: middle' align='center'><img id='DialogLoadingDivImg' alt='' src='/_imgs/AdvFind/progress.gif'><br>Loading...</td></tr></tbody></table></div></div>");

But it also requires some additional routines to close such dialog properly.

Is there any Microsoft-provided javascript methods to open such a iframe?

shytikov
  • 9,155
  • 8
  • 56
  • 103

3 Answers3

7

Here is the example of displaying web resource in such dialog box.

In the parent window:

var src = <Relative_Url_of_the_Webresource>;
var DialogOptions = new Xrm.DialogOptions(); 
DialogOptions.width = 500;
DialogOptions.height = 400;
Xrm.Internal.openDialog(src, DialogOptions, null, null, CallbackFunction);

function CallbackFunction(returnValue){ }

Also, you have to include ClientGlobalContext.js.aspx in your web resource, for example:

<script type="text/javascript" src="/webresources/ClientGlobalContext.js.aspx"></script> 

For passing the return value from the dialog box to the parent window:

Mscrm.Utilities.setReturnValue(result);
try {
    closeWindow(true); //Close the dialog box
}
catch (e) { }
G_Iashyn
  • 178
  • 5
  • Looks much cleaner! Thank you! – shytikov Jun 24 '14 at 14:22
  • 2
    When I open a WebResource like this, it appends "?dType=1" to the URL which causes an internal server error as the parameter seems to be invalid (GET http://crm2013/Org/WebResources/tv_closeEmail?dType=1 500 (Internal Server Error) ). Any idea how I can prevent this? – Michael Klement Jul 09 '14 at 13:10
  • FYI this worked for reading in dialogArguments window.getInlineDialogArguments() – Andrew Sep 29 '14 at 07:58
  • Michael Barth -Did you solve the issue in the end we are now having the same on a HTTPS site? – Andrew Oct 01 '14 at 20:35
  • 3
    @Andi: Yeah, actually I found it out just now as I was giving it another try. The thing is, you need to pass the webresource url like this "$webresource:new_yourWebResource" (the prefix "$webresource:" is important!). Then no "dType" parameter will be attached to the URL. – Michael Klement Nov 20 '14 at 15:02
2

Of course this is unsupported and methods are not documented but you can try to use following approach - http://a33ik.blogspot.com/2014/05/show-your-dialog-in-crm-2013-modal-style.html

Here is the code:

if (typeof Custom == "undefined") {
    Custom = {
        OpenDialog: function (webresource) {
            var $v_0 = new Mscrm.CrmDialog(Mscrm.CrmUri.create(webresource), window, 370, 370, null);
            $v_0.show();
        },
        __namespace: true
    };
}

Sample of usage:

Custom.OpenDialog("/webresources/new_webresource.htm");
Alex
  • 23,004
  • 4
  • 39
  • 73
Andrew Butenko
  • 5,048
  • 1
  • 14
  • 13
1

There is no supported way to programmatically open lookup dialogs.

The Dynamics CRM 2013 SDK lists the lookup control methods that are supported:

  1. addCustomFilter
  2. addCustomView
  3. getDefaultView
  4. setDefaultView

You can also add presearch events.

Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42