If you need to open a web resource as a window or as a dialog in Dynamics CRM 2011 you can use these methods. But you need to know somethings:
- When you open a dialog you cannot use anymore F12 key to debug javascript code in your called webresource.
- An opened dialog cannot refresh or close a parent window. If you need to refresh the parent entity form you need to use openWebResourceAsWindow() insteed of openWebResourceAsDialog(). because, in the window mode you can use :
window.opener.location.reload();
Source Code
- /// <summary>
- /// Allow to open a html webresource as a dialog box
- /// </summary>
- /// <param name="webResourceName"><b>string</b>: HTML web resource logical name like (new_webresource.html)</param>
- /// <param name="webResourceData"><b>string</b>: URI Encoded web resource data using encodeURIComponent() that begins with "?"</param>
- /// <param name="width"><b>int</b>: the width of the window without (px)</param>
- /// <param name="height"><b>int</b>: the height of the window without (px)</param>
- /// <param name="viewScrollbars"><b>bool</b>: allow to view the scrollbars (true or false)</param>
- /// <param name="viewToolbar"><b>bool</b>: allow to view the toolbar (true or false)</param>
- /// <param name="viewMenubar"><b>bool</b>: allow to view the menubar (true or false)</param>
- /// <param name="viewLocation"><b>bool</b>: allow to view the location (true or false)</param>
- function openWebResourceAsDialog(webResourceName, webResourceData, width, height, viewScrollbars, viewToolbar, viewMenubar, viewLocation) {
- var $v_0 = Mscrm.CrmUri.create(String.format("$webresource:{0}", webResourceName));
- if (!isNullOrEmptyString(webResourceData)) {
- $v_0 = $v_0 + webResourceData;
- }
- var parameters = "";
- if (viewScrollbars !== undefined && viewScrollbars == true) {
- parameters = "scrollbars=1,";
- }
- else {
- parameters = "scrollbars=0,";
- }
- if (viewToolbar !== undefined && viewToolbar == true) {
- parameters += "toolbar=1,";
- }
- else {
- parameters += "toolbar=0,";
- }
- if (viewMenubar !== undefined && viewMenubar == true) {
- parameters += "menubar=1,";
- }
- else {
- parameters += "menubar=0,";
- }
- if (viewLocation !== undefined && viewLocation == true) {
- parameters += "location=1";
- }
- else {
- parameters += "location=0";
- }
- return openStdDlg($v_0, null, width, height, true, false, parameters);
- }
- /// <summary>
- /// Allow to open a html webresource as a window
- /// </summary>
- /// <param name="webResourceName"><b>string</b>: HTML web resource logical name like (new_webresource.html)</param>
- /// <param name="webResourceData"><b>string</b>: URI Encoded web resource data using encodeURIComponent() that begins with "?"</param>
- /// <param name="width"><b>int</b>: the width of the window without (px)</param>
- /// <param name="height"><b>int</b>: the height of the window without (px)</param>
- /// <param name="viewScrollbars"><b>bool</b>: allow to view the scrollbars (true or false)</param>
- /// <param name="viewToolbar"><b>bool</b>: allow to view the toolbar (true or false)</param>
- /// <param name="viewMenubar"><b>bool</b>: allow to view the menubar (true or false)</param>
- /// <param name="viewLocation"><b>bool</b>: allow to view the location (true or false)</param>
- function openWebResourceAsWindow(webResourceName, webResourceData, width, height, viewScrollbars, viewToolbar, viewMenubar, viewLocation) {
- var $v_0 = Mscrm.CrmUri.create(String.format("$webresource:{0}", webResourceName));
- if (!isNullOrEmptyString(webResourceData)) {
- $v_0 = $v_0 + webResourceData;
- }
- var parameters = "";
- if (viewScrollbars !== undefined && viewScrollbars == true) {
- parameters = "scrollbars=1,";
- }
- else {
- parameters = "scrollbars=0,";
- }
- if (viewToolbar !== undefined && viewToolbar == true) {
- parameters += "toolbar=1,";
- }
- else {
- parameters += "toolbar=0,";
- }
- if (viewMenubar !== undefined && viewMenubar == true) {
- parameters += "menubar=1,";
- }
- else {
- parameters += "menubar=0,";
- }
- if (viewLocation !== undefined && viewLocation == true) {
- parameters += "location=1";
- }
- else {
- parameters += "location=0";
- }
- return openStdWin($v_0, null, width, height, parameters)
- }
- /// <summary>
- /// Allows to open the custom Discount Dialog
- /// </summary>
- function openDiscountDialog() {
- if (Xrm.Page.data.entity.getIsDirty()) {
- alert("One or more fields are modified. Please save the form.");
- return;
- }
- var entityId = Xrm.Page.data.entity.getId();
- var entityName = Xrm.Page.data.entity.getEntityName();
- var customParameters = encodeURIComponent("?EntityName=" + entityName + "&EntityId=" + entityId);
- openWebResourceAsDialog("njl_discountDialog.html", customParameters, 280, 130, false, false, false, false);
- }
- /// <summary>
- /// Allows to open the custom Incident Resolution Window
- /// </summary>
- function openIncidentResolutionWindow() {
- if (Xrm.Page.data.entity.getIsDirty()) {
- alert("One or more fields are modified. Please save the form.");
- return;
- }
- var entityId = Xrm.Page.data.entity.getId();
- var entityName = Xrm.Page.data.entity.getEntityName();
- var customParameters = encodeURIComponent("?EntityName=" + entityName + "&EntityId=" + entityId);
- openWebResourceAsWindow("njl_incidentResolutionWindow.html", customParameters, 400, 280, true, false, false, true);
- }
Enjoy yourself,
N.JL
Never say there is nothing beautiful in the world anymore. There is always something to make you wonder in the shape of a tree, the trembling of a leaf. See the link below for more info.
ReplyDelete#anymore
www.ufgop.org
Excellent! Help me so much!! Congrats!!
ReplyDelete