Monday, August 27, 2012

Prevent window from closing on Save and Close.



function OnSave(event) {
         // Cancel the save operation.
         event.returnValue = false;
         return false;
}
or
function OnSave(event) {
        // Cancel the save operation.
        event.getEventArgs().preventDefault();
        return false;
}
My understanding is that event.returnValue = false; is CRM 4.0 syntax (still works in CRM 2011), while event.getEventArgs().preventDefault(); is CRM 2011 syntax

Note: The pass execution context as first parameter checkbox is very important to this process. Without it, it will not work.

Thursday, August 23, 2012

How to change the form header/footer color in MS CRM 2011 or Set Gradient color in MS CRM 2011 Header and Footer.


Lets I am creating in Account Entity.

First Create a Css called Header.css  using Web Resource in CRM.I give the Name new_Header in CRM.

.ms-crm-Form-HeaderContainer{ 
   filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffB3CAEC, 

endColorstr=#fff6f8faE); 
}

.ms-crm-Form-Footer{ 
   filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffB3CAEC, 

endColorstr=#fff6f8faE); 
   background-image: none; 
}

Now Create a Javascript using Web Resource that call this css during OnLoad Event.
I give Name new_HeaderJS in CRM.The Javascript is like this

function load_css_file(filename) { 
    var fileref = document.createElement("link") 
    fileref.setAttribute("rel", "stylesheet") 
    fileref.setAttribute("type", "text/css") 
    fileref.setAttribute("href", filename) 
    document.getElementsByTagName("head")[0].appendChild(fileref) 

}

function myFormOnLoad() { 

    load_css_file('/WebResources/new_Header'); 

}

Now Open Account Form and add the Library new_HeaderJS in Form Properties and add Event Handler and Pass a Function Name=myFormOnLoad.Then Save it and Publish it.

The Output is Like this.

Monday, August 13, 2012

Set the Default Time in Date type Attribute.

Introduction
                   Today i am going to show you the javascript of set the time in Date Field.Some times back i have requirement of set the time 7:00 when i select any Date From Date Field.If you check then if you select any date the time 00:00 show you.but i have reqirement that i have to set default time value 7:00 when i select the date.and that should only happen when you creating new record.so you have to call the Function in Onchange Event of date Field and use of the FormType for only call it on Create.


function SetDefaultTimeValue()
{
var FORM_TYPE_CREATE = 1;

var formType = Xrm.Page.ui.getFormType();
if (formType == FORM_TYPE_CREATE)
{
var att = Xrm.Page.getAttribute('new_setnextcall');//new_setnextcall is Field name
var curDate = att.getValue();
curDate.setHours(7,0,0);
att.setValue(curDate);
}
}

Now create a new record where this function and field is then and select any date you will see output like


Activate or Deactivate record in CRM 2011

We can Activate\Deactivate record. Below is the code snippet.


For Ex.


  Entity entNewLead = new Entity("lead");
  entNewLead["leadid"] = new Guid(leadduns["leadid"].ToString());
  entNewLead["statuscode"] = new OptionSetValue(2);
  entNewLead["statecode"] = new OptionSetValue(1);
  _service.Update(entNewLead);