Sunday, July 17, 2011

how to custom a due date (or any date) on the records of the home grid in MS CRM 4.0 also in 2011

Suppose you have a field on an entity. and you want to populate the records by highlighting that field value on basis of some logic.
In my case am considering the Due Date of an entity, if the due date is earlier than today , then the value in the Grid will be red.

1st Step
include the JS file in the HomePage.aspx in the _root/ of the installed MS CRM.
in that include the code
function window.onload()
{
updateDueDate();
}
2nd step
wrtite the JS code

//coloring the due date and also doing the alternate grid clor
function colorizedduedate(mytable, mycolumn) {
var loTable=document.getElementById(mytable);
var j
var datetoday = new Date;
var datedue = new Date;
var dateduestr
var datetodaystr
var colPatient= crmGrid.InnerGrid.FindColumnIndex("<id of the primary attribute for that entity, fo me its new_patientid>");

var month = datetoday.getMonth() + 1;
var day = datetoday.getDate();
var year = datetoday.getFullYear();

if (month<10) {
month = '0' + month;
}

if (day<10) {
day = '0' + day;
}
if (loTable.rows.length < 1)
{
return;
}
for (var j = 0; j < loTable.rows.length; j++) {
x=loTable.rows[j].cells;
if (typeof(x[mycolumn]) =="undefined") { return;}
dateduestr=x[mycolumn].innerHTML;
if (typeof(dateduestr) =="undefined") { return;}
if (dateduestr != '')
{
dateduestr = dateduestr.replace('<NOBR>','');
dateduestr = dateduestr.replace('<NOBR class=datetime>','');
dateduestr = dateduestr.replace('</NOBR>','')

var datearr = dateduestr.split("/"); //dd/mm/yyyy to mm/dd/yyyy
dateduestr = datearr[1]+ "/" + datearr[0] + "/" + datearr[2];

var datearr2 = dateduestr.split(" "); //remove time
datedue = new Date(dateduestr);
if (datetoday > datedue)
{
x[mycolumn].innerHTML='<span style=\'color:#FF0000\'>'+x[mycolumn].innerHTML+'</span>';
}
}

var cols = loTable.rows[j].getElementsByTagName("NOBR");

if ((j % 2) == 0) {
loTable.rows[j].style.backgroundColor = "#EEEEEE";
grid.childNodes[i].colourised = true;
}
else {
}

}
}

//only coloring alternate colors to the grid
function colorizedotherentity(mytable) {
var loTable = document.getElementById(mytable);
var j

var grid = document.getElementById(mytable).lastChild;
for (var i = 0; i < grid.childNodes.length; i++)
{
if ((i % 2) == 0) {
grid.childNodes[i].style.backgroundColor = "#EEEEEE";
grid.childNodes[i].colourised = true;
}
else {

}
}
}


function CheckTaskListMenus() {
if (_currentTypeCode == <check the objecttype code as account is 1> ) {
//Hide the filter (A,B..Z) at the bottom of the grid
document.getElementById("crmGrid_JumpBar").style.display = "none";

if (document.getElementById('_MBdoActioncrmGrid10051assign') != null) {
document.getElementById('_MBdoActioncrmGrid10051assign').style.display = "none";
}

var colduedate = crmGrid.InnerGrid.FindColumnIndex("new_datedue");
colorizedduedate("gridBodyTable", colduedate);

}
else {
colorizedotherentity("gridBodyTable");
}
}
//main function which will be called from the HomePage.aspx
function updateDueDate(){
CheckTaskListMenus();
crmGrid.attachEvent("onrefresh", OnGridRefreshX);
}

hope this will help.

No comments:

Post a Comment