Showing posts with label Webresource. Show all posts
Showing posts with label Webresource. Show all posts

Thursday, April 3, 2014

Open a html webresource as a window or a dialog box in CRM 2011.

Hi Guys,

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
  1.  
  2. /// <summary>
  3. /// Allow to open a html webresource as a dialog box
  4. /// </summary>
  5. /// <param name="webResourceName"><b>string</b>: HTML web resource logical name like (new_webresource.html)</param>
  6. /// <param name="webResourceData"><b>string</b>: URI Encoded web resource data using encodeURIComponent() that begins with "?"</param>
  7. /// <param name="width"><b>int</b>: the width of the window without (px)</param>
  8. /// <param name="height"><b>int</b>: the height of the window without (px)</param>
  9. /// <param name="viewScrollbars"><b>bool</b>: allow to view the scrollbars (true or false)</param>
  10. /// <param name="viewToolbar"><b>bool</b>: allow to view the toolbar (true or false)</param>
  11. /// <param name="viewMenubar"><b>bool</b>: allow to view the menubar (true or false)</param>
  12. /// <param name="viewLocation"><b>bool</b>: allow to view the location (true or false)</param>
  13. function openWebResourceAsDialog(webResourceName, webResourceData, width, height, viewScrollbars, viewToolbar, viewMenubar, viewLocation) {
  14.     var $v_0 = Mscrm.CrmUri.create(String.format("$webresource:{0}", webResourceName));
  15.  
  16.     if (!isNullOrEmptyString(webResourceData)) {
  17.         $v_0 = $v_0 + webResourceData;
  18.     }
  19.     var parameters = "";
  20.     if (viewScrollbars !== undefined && viewScrollbars == true) {
  21.         parameters = "scrollbars=1,";
  22.     }
  23.     else {
  24.         parameters = "scrollbars=0,";
  25.     }
  26.     if (viewToolbar !== undefined && viewToolbar == true) {
  27.         parameters += "toolbar=1,";
  28.     }
  29.     else {
  30.         parameters += "toolbar=0,";
  31.     }
  32.     if (viewMenubar !== undefined && viewMenubar == true) {
  33.         parameters += "menubar=1,";
  34.     }
  35.     else {
  36.         parameters += "menubar=0,";
  37.     }
  38.     if (viewLocation !== undefined && viewLocation == true) {
  39.         parameters += "location=1";
  40.     }
  41.     else {
  42.         parameters += "location=0";
  43.     }
  44.  
  45.     return openStdDlg($v_0, null, width, height, true, false, parameters);
  46. }
  47.  
  48. /// <summary>
  49. /// Allow to open a html webresource as a window
  50. /// </summary>
  51. /// <param name="webResourceName"><b>string</b>: HTML web resource logical name like (new_webresource.html)</param>
  52. /// <param name="webResourceData"><b>string</b>: URI Encoded web resource data using encodeURIComponent() that begins with "?"</param>
  53. /// <param name="width"><b>int</b>: the width of the window without (px)</param>
  54. /// <param name="height"><b>int</b>: the height of the window without (px)</param>
  55. /// <param name="viewScrollbars"><b>bool</b>: allow to view the scrollbars (true or false)</param>
  56. /// <param name="viewToolbar"><b>bool</b>: allow to view the toolbar (true or false)</param>
  57. /// <param name="viewMenubar"><b>bool</b>: allow to view the menubar (true or false)</param>
  58. /// <param name="viewLocation"><b>bool</b>: allow to view the location (true or false)</param>
  59. function openWebResourceAsWindow(webResourceName, webResourceData, width, height, viewScrollbars, viewToolbar, viewMenubar, viewLocation) {
  60.     var $v_0 = Mscrm.CrmUri.create(String.format("$webresource:{0}", webResourceName));
  61.  
  62.     if (!isNullOrEmptyString(webResourceData)) {
  63.         $v_0 = $v_0 + webResourceData;
  64.     }
  65.     var parameters = "";
  66.     if (viewScrollbars !== undefined && viewScrollbars == true) {
  67.         parameters = "scrollbars=1,";
  68.     }
  69.     else {
  70.         parameters = "scrollbars=0,";
  71.     }
  72.     if (viewToolbar !== undefined && viewToolbar == true) {
  73.         parameters += "toolbar=1,";
  74.     }
  75.     else {
  76.         parameters += "toolbar=0,";
  77.     }
  78.     if (viewMenubar !== undefined && viewMenubar == true) {
  79.         parameters += "menubar=1,";
  80.     }
  81.     else {
  82.         parameters += "menubar=0,";
  83.     }
  84.     if (viewLocation !== undefined && viewLocation == true) {
  85.         parameters += "location=1";
  86.     }
  87.     else {
  88.         parameters += "location=0";
  89.     }
  90.     return openStdWin($v_0, null, width, height, parameters)
  91. }
  92.  
  93. /// <summary>
  94. /// Allows to open the custom Discount Dialog
  95. /// </summary>
  96. function openDiscountDialog() {
  97.     if (Xrm.Page.data.entity.getIsDirty()) {
  98.         alert("One or more fields are modified. Please save the form.");
  99.         return;
  100.     }
  101.     var entityId = Xrm.Page.data.entity.getId();
  102.     var entityName = Xrm.Page.data.entity.getEntityName();
  103.     var customParameters = encodeURIComponent("?EntityName=" + entityName + "&EntityId=" + entityId);
  104.     openWebResourceAsDialog("njl_discountDialog.html", customParameters, 280, 130, false, false, false, false);
  105. }
  106.  
  107. /// <summary>
  108. /// Allows to open the custom Incident Resolution Window
  109. /// </summary>
  110. function openIncidentResolutionWindow() {
  111.     if (Xrm.Page.data.entity.getIsDirty()) {
  112.         alert("One or more fields are modified. Please save the form.");
  113.         return;
  114.     }
  115.     var entityId = Xrm.Page.data.entity.getId();
  116.     var entityName = Xrm.Page.data.entity.getEntityName();
  117.     var customParameters = encodeURIComponent("?EntityName=" + entityName + "&EntityId=" + entityId);
  118.     openWebResourceAsWindow("njl_incidentResolutionWindow.html", customParameters, 400, 280, true, false, false, true);
  119. }

Enjoy yourself,
N.JL

Thursday, June 27, 2013

How to use Fiddler to debug CRM 2011 Javascript and HTML Webresources


Hi Guys,

In order to properly develop JavaScript and/or Html webresources, a CRM 2011 developer needs to make many publications on CRM development server, sometimes, with many errors. And when a team works on the same server, especially on the same entity, that can make the work troublesome and make any back slowly during these publications.

Using Fiddler 2 locally as an auto-responder is the solution.  


As a web debugging proxy, Fiddler will intercept any session (web call) outgoing form your local machine. And it can redirect some session to call instead of letting it out to web server. This is the role of the Auto-Responder.



And now, follow these steps:


  1. Launch Fiddler 2
  2. Make a Filter to show only sessions going to CRM Server like this:

  3. After this operation, select all session in the “Web Sessions” list and remove theme.

  4. Open IE and go to “ Inernet Option”, and delete “Temporary Internet Files and Website Files” like this :


  5. Back to Fiddler and click to Autoresponder tab.
  6. Ckeck this two options

  7. In Web Sessions List, Select Session line corresponding to your javascript/Html webresource that you want to work on then, drag and drop it in " If URI Matchs..." list.


  8. That add a line in this list. This line starts With the keyword : "EXACT". The same line is added in the first combbox of the "Rule Editor", and a in the second combobox this string "*200-SESSION_211" is added.


  9. You need to replace EXACT keyword by REGEX keyword In the first combobox, then replace the entire URL string up before the name of the WebResources by "*/" and finally you need to add ".*" in the end of string like this : 
  10. EXACT:http://ServerName/OrgName/WebResources/new__common.utilities.js
    become
    REGEX:.*/new_common.utilities.js.*



  11. After that, in the second combobox, put the local file path of your webresource like this:




  12. Finally click to Save.
Repeat this operation for all your webresources that you want to work on. and not forget to empty Temporary IE Files everytime you want to put a new webresource.

Have a nice Day.

I hope that this post helps you.

N.JL