23 February 2008

Show how many activities/history associated with a record


Sometimes we want to see how many activities/history associated with a record, it's nice to have a number just like the Outlook Inbox.

Here's the code, it works fine on both CRM 3.0 and 4.0 (slightly different). Please notice that you have to reload the record to get the current number after you add/close an activity.


var buXml = GetRegardingActivity();

if(buXml != null)
{
var buNodes = buXml.selectNodes("//BusinessEntity/statecode"); // CRM 3.0

//var buNodes = buXml.selectNodes("//BusinessEntity/q1:statecode"); // CRM 4.0
var iActivity = 0;
var iHistory = 0;

if(buNodes != null )
{
/*get values*/
for( i = 0; i < buNodes.length; i++)
{
switch(buNodes[i].text)
{
case "Open" : iActivity++; break;
case "Scheduled" : iActivity++; break;
case "Completed" : iHistory++; break;
case "Canceled" : iHistory++; break;
}
}

if(document.getElementById('navActivities') != null)
{
document.getElementById('navActivities').getElementsByTagName('NOBR')[0].innerText = document.getElementById('navActivities').getElementsByTagName('NOBR')[0].innerText + " (" + iActivity + ")";
}

if(document.getElementById('navActivityHistory') != null)
{
document.getElementById('navActivityHistory').getElementsByTagName('NOBR')[0].innerText = document.getElementById('navActivityHistory').getElementsByTagName('NOBR')[0].innerText + " (" + iHistory + ")";
}
}
}

function GetRegardingActivity()
{
var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
" <soap:Body>" +
" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\" xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" +
" <q1:EntityName>activitypointer</q1:EntityName>" +
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
" <q1:Attributes>" +
" <q1:Attribute>statecode</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:Criteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>regardingobjectid</q1:AttributeName>" +
" <q1:Operator>Equal</q1:Operator>" +
" <q1:Values>" +
" <q1:Value xsi:type=\"xsd:string\">" + crmForm.ObjectId + "</q1:Value>" +
" </q1:Values>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:Criteria>" +
" </query>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;
return resultXml;
}

01 February 2008

Happy Chinese New Year: 2008 - The Year of The Rat


7th Feb 2008: Chinese New Year or Spring Festival (simplified Chinese: ; traditional Chinese: ; pinyin: Chūnjié), or the Lunar New Year (simplified Chinese: ; traditional Chinese: ; pinyin: Nónglì xīnnián), is the most important of the traditional Chinese holidays. It is an important holiday in East Asia. The festival traditionally begins on the first day of the first lunar month (Chinese: 正月; pinyin: zhēng yuè) in the Chinese calendar and ends on the 15th; this day is called Lantern Festival (simplified Chinese: 元宵; traditional Chinese: 元宵; pinyin: yuánxiāojié). Chinese New Year's Eve is known as Chúxī (除夕). Chu literally means "change" and xi means "Eve".

The Chinese calendar is based on a combination of lunar and solar movements. The lunar cycle is about 29.5 days. In order to "catch up" with the solar calendar the Chinese insert an extra month once every few years (seven years out of a 19-yearcycle). This is the same as adding an extra day on leap year. This is why, according to the solar calendar, the Chinese New Year falls on a different date each year.