Saturday, August 21, 2010

Getting the actual day of the week from a date field

It's the simple things that I sometimes get stuck on. For the longest time, I couldn't figure out how to garner the actual day of the week from a date field value.

Now I share how ridiculously simple it is using Jscript.

var date = crmForm.all.pai_dateworked.DataValue;
var pai_name
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
pai_name = weekday[date.getDay()];
crmForm.all.pai_name.DataValue = pai_name;

Saturday, August 14, 2010

Save the last viewed tab

I've had alot of clients to ask me about this. Keep in mind that this is really for CRM 4.0.
The scenario goes that you may be asked to perform some save events that happens on a form. The form has a couple of tabs, and the save event happens on the 3rd tab. The form reloads back on the first tab. It gets pretty annoying especially when you have alot of tabs (not saying some CRM dev might have hacked the number of tabs on a form).





function OnCrmPageLoad()
{
if( crmForm.FormType == 2)
RetainTab();
}

function RetainTab()
{
crmForm.attachEvent( "onsave" , OnCrmPageSave );
var regTab = new RegExp( window.name + "=(\\d)","gi");
regTab.exec(document.cookie);
var tab = document.getElementById("tab"+RegExp.$1+"Tab");
if( tab ) tab.click();
}

function OnCrmPageSave()
{
var crmTabBar = document.all.crmTabBar;
for(var i = 0 ; i < cookie =" window.name+"="+i;
break;
}
}
}

OnCrmPageLoad();