title: Get The Current User ID and Server URL in an HTML Page - CRM 2011
body: <p>I'm trying to launch a dialog from an HTML page in Microsoft Dynamics CRM 2011, and to be honest I'm not getting anywhere with it.</p>
  
  <p>Here is my HTML page:</p>
  
  <pre><code>&lt;HTML&gt;&lt;HEAD&gt;
  &lt;META charset=utf-8&gt;
  &lt;SCRIPT&gt;
  function getServerUrl(){
      var context, crmServerUrl;
      if (typeof GetGlobalContext != "undefined") {
          context = GetGlobalContext();
      }
      else if (typeof Xrm != "undefined") {
          context = Xrm.Page.context;
      }
      else {
          throw new Error("CRM context is not available.");
      }
  
      if (context.isOutlookClient() &amp;&amp; !context.isOutlookOnline()) {
          crmServerUrl = window.location.protocol + "//" + window.location.host;
      } else {
          crmServerUrl = context.getServerUrl();
          crmServerUrl = crmServerUrl.replace(/^(http|https):\/\/([_a-zA-Z0-9\-\.]+)(:([0-9]{1,5}))?/, window.location.protocol + "//" + window.location.host);
          crmServerUrl = crmServerUrl.replace(/\/$/, ""); // remove trailing slash if any
      }
      return crmServerUrl;
  }
  
  function LaunchDialog()
   {
  var string = getServerUrl();
  alert(string);
  var url="/" + getOrg() + "/cs/dialog/rundialog.aspx?DialogId=%7b7B189BA4-84B4-4E41-AE85-2066A379E502%7d&amp;EntityName=systemuser&amp;ObjectId=" + getUser();
      //window.open(url, "", "status=no,scrollbars=no,toolbars=no,menubar=no,location=no");
  alert(url);
      //window.open(url);
   }
  function getOrg() {
  alert("Called");
          ///&lt;summary&gt;
          /// get organisation
          ///&lt;/summary&gt;
  
          var Org = "";
          if (typeof GetGlobalContext == "function") {
              var context = GetGlobalContext();
              Org = context.getOrgUniqueName();
          }
          else {
              if (typeof Xrm.Page.context == "object") {
                  Org = Xrm.Page.context.getOrgUniqueName();
              }
              else
              { throw new Error("Unable to access Organisation name"); }
          }
         alert("About to return org");
          return Org;
      }
  
  function getUser() {
  alert("Called 1");
          ///&lt;summary&gt;
          /// get logged in user
          ///&lt;/summary&gt;
  
          var User = "";
          if (typeof GetGlobalContext == "function") {
              var context = GetGlobalContext();
              User = context.getUserId();
          }
          else {
              if (typeof Xrm.Page.context == "object") {
                  User = Xrm.Page.context.getUserId();
              }
              else
              { throw new Error("Unable to access the UserId"); }
          }
        alert("End User");
          return User;
      }   
  &lt;/SCRIPT&gt;
  &lt;/HEAD&gt;
  &lt;BODY contentEditable=true&gt;
  &lt;H1&gt;Create Record&lt;/H1&gt;
  &lt;P&gt;&lt;BUTTON onclick=LaunchDialog()&gt;Try it&lt;/BUTTON&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;
  </code></pre>
  
  <p>Web-programming is my strongest talent by any means, so can anyone provide any suggestions as to how I can solve this?</p>