title: Dynamics CRM: Javascript triggers open dialog
body: <p>I am trying to create javascript to open a dialog. </p>
  
  <p>once the value of a field called 'new_mstatus' on the current record is equal to 'Inactive' and user intends to open this record,  a dialog will open. </p>
  
  <pre class="lang-js prettyprint-override"><code>function opendialog() {
     if(Xrm.Page.ui.getFormType() == 1)
     {
         Xrm.Page.data.entity.save(null);
         return;
     }
  
     // If inactive then trigger dialog
     if (Xrm.Page.getAttribute("new_mstatus").getValue() == 'Inactive') {
  
         window.open("/" + Xrm.Page.context.getOrgUniqueName() + "/cs/dialog/rundialog.aspx?DialogId=%7b840D55C6-8307-450B-977F-6A9C9844CCE7%7d&amp;EntityName=appointment&amp;ObjectId=" + Xrm.Page.data.entity.getId());
  
         // Set as being displayed so it doesn't trigger again on load
         Xrm.Page.getAttribute("new_displayeddialog").setValue(true);
  
     }
  }
  </code></pre>
  
  <p>but it doesnt work. even no error popup. </p>
  
  <p>can someone give me a hand with this?</p>
  
  <p>Thanks a lot.</p>