CRM 2011: Launch Dialog from JavaScript


/ Published in: JavaScript
Save to your folder(s)

How to launch custom dialog from JavaScript (for example from custom RibbonButton)


Copy this code and paste it in your HTML
  1. function launchModalDialog(dialogId, typeName, recordId)
  2. {
  3. // Server Url
  4. var serverUrl = Xrm.Page.context.getServerUrl();
  5.  
  6. // Sanitize RecordId
  7. recordId = recordId.replace("{", "");
  8. recordId = recordId.replace("}", "");
  9.  
  10. // Sanitize DialogId
  11. dialogId = dialogId.replace("{", "");
  12. dialogId = dialogId.replace("}", "");
  13.  
  14. // Create Url
  15. var serverUri = serverUrl + '/cs/dialog/rundialog.aspx';
  16. var dialogUri = serverUri + '?DialogId=%7b' + dialogId.toUpperCase() +'%7d&EntityName=' + typeName + '&ObjectId=%7b' + recordId + '%7d';
  17.  
  18. window.showModalDialog(dialogUri);
  19.  
  20. // Reload form
  21. window.location.reload(true);
  22. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.