Useful Javascripts for CRM 2011

// Get the form type GetFormType: function () { var FORM_TYPE_CREATE = 1; var FORM_TYPE_UPDATE = 2; var FORM_TYPE_READ_ONLY = 3; var FORM_TYPE_DISABLED = 4; var FORM_TYPE_QUICK_CREATE = 5; var FORM_TYPE_BULK_EDIT = 6; var formType = Xrm.Page.ui.getFormType(); if (formType == FORM_TYPE_CREATE) { alert("This record has not yet been created."); } else { alert("This record exists …

Get the CRM server url from Silverlight [If the silverlight page is in a form]

private static String GetServerUrlFromCrmContext() { try { // If the Silverlight is in a form, this will get the server url ScriptObject xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm"); if (xrm != null) { ScriptObject page = (ScriptObject)xrm.GetProperty("Page"); ScriptObject pageContext = (ScriptObject)page.GetProperty("context"); String serverUrl = (String)pageContext.Invoke("getServerUrl"); return serverUrl; } else { goto DevUrl; } } catch { goto DevUrl; …

Adding a custom button to CRM 2011 Form

Adding a button to a CRM Form is quite challenging as we don't have any IDE to design it. But still it's possible using JavaScript.Here's the JavaScript code for that.// Create the button, using the new_custombutton field as a container        CreateButtonCRM5('swpmt_cancelddi', 'Cancel DDI', '75 px', '16_cancel.png', CustomClickFunction);// Custom Functionfunction CustomClickFunction() {    var response …