- Posts tagged javascript
- Explore javascript on posterous
Add a CRM Calendar to a dashboard
Dashboards in Dynamics CRM 2011 are a great way to visualize data. Did you know that they can also be used to view pretty much any other web content?
I’ve recently had a requirement to add the CRM Calendar to a dashboard. I could have simply added a list of appointment activities to the dashboard, but the actual calendar control looks a lot nicer.
To do this, first we need to get the URL of the Calendar page. Load up the IE developer tools (F12 in IE9) and start a profiler. Now navigate to the calendar in CRM and click on ‘Month’, ‘Week’ and ‘Day’ (we want the URL for each page).
Stop the profiler and take a look at the results As you can see, we’ve got the URLs of the 3 calendar views needed for the dashboard. The URL seems to contain a parameter for the current date in ISO8601 format (YYYY-MM-DDThh:mm:ss). We’ll have to deal with that inside of our web resource.Set age based on date of birth
I had a requirement to set an 'Age' attribute based on the contents of the Date of Birth field on Contacts. The below script in the On Save, On Load or On Change will do this.
if(crmForm.all.birthdate.DataValue != null)
{
var now = new Date(); //get today's date
var birthday = crmForm.all.birthdate.DataValue; //get the dob value
var diff = now.getMonth() - birthday.getMonth(); //have they had their birthday already this year?
if(diff > -1) //if they've had a birthday this year
{
var bd1 = now.getFullYear() - birthday.getFullYear();
crmForm.all.new_age.DataValue =bd1.toString(); //set the new_age attribute
}
else //if they have not had a birthday yet this year
{
var bd2 = now.getFullYear() - birthday.getFullYear() - 1;
crmForm.all.new_age.DataValue =bd2.toString();
}
}
IE8 crashing when using picklists in Advanced Finds
I've been having an issue where IE8 would crash when trying to use picklists in advanced finds (see below example).
It may not be a common issue, but I posted it on the MS partner forums and got the below response which has fixed it for me, so hopefully it will help someone else out too!
Edit AdvFind.aspx and add the following code. AdvFind.aspx can be found in the CRM web directory\AdvancedFind
NOTE: The code needs to be added right below function window.onload(){
<% if (Request.Params["AutoRun"] != "False")
{
%>
if (location.href.indexOf("?") > 0)
location.href = location.href + "&AutoRun=False";
else
location.href = location.href + "?AutoRun=False";
<%
}
%>
View originating lead notes on a contact
Our sales guys wanted a way to view originating lead notes against the Contacts created from Leads. I added a new tab to the contact containing an Iframe and used the below javascript to display the notes from the originating lead.
var lookupItem = new Array;
//set the lookup to the originating lead
lookupItem = crmForm.originatingleadid.DataValue;
if (lookupItem != null)
{
//display the originating lead notes in the iframe 'IFRAME_LeadNotes'
crmForm.all.IFRAME_LeadNotes.src="/_controls/notes/notesdata.aspx?id="+ lookupItem[0].id + "&ParentEntity=3&EnableInlineEdit=false&EnableInsert=false";
}
else
{
//if there is no originating lead, hide the tab
crmForm.all.IFRAME_LeadNotes.src="about:blank";
tab7Tab.style.display = "none";
}
Google Maps in CRM
I wanted a quick way of viewing an Account’s location so I created a link to Google maps based on the postcode of the Account.
First of all, create an nvarchar/URL attribute called new_googlemaps, stick it somewhere on your Account form and then put the below javascript into the Account OnLoad event
crmForm.all.new_googlemaps.DataValue = “http://maps.google.com/maps?q=”+crmForm.all.address1_postalcode.DataValue;
It’s pretty basic but does exactly what I want. I’m going to look at embedding the actual map in an iframe when I get the chance
Edit: it turns out that Richard Knudson has covered embedding maps already on his site!





