Archive for the ‘CRM 4’ Category
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.
Note: You will need to change the “birthdate” and “new_age” field names to the relavant fields on your form.
CRM 2011
function calcBirthday() { if(Xrm.Page.getAttribute("birthdate").getValue() != null) { var now = new Date(); //get today's date var birthday = Xrm.Page.getAttribute("birthdate").getValue(); //get the dob value var diff = now.getMonth() - birthday.getMonth(); //have they had their birthday already this year? var age; //use to store age if (diff == 0) //if birthday is this month, compare the days instead { diff = now.getDate() - birthday.getDate(); } if(diff > -1) //if they've had a birthday this year { age = now.getFullYear() - birthday.getFullYear(); } else //if they have not had a birthday yet this year { age = now.getFullYear() - birthday.getFullYear() - 1; } Xrm.Page.getAttribute("new_age").setValue(age.toString()); //set the new_age attribute } }
CRM 4
function calcBirthday(){ 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 == 0) //if birthday is this month, compare the days instead { diff = now.getDate() - birthday.getDate(); } 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 directoryAdvancedFind
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"; <% } %>
CRM pop-ups in new tabs
With Internet Explorer, you have the option to open all pop ups in a new tab rather than a new window. I find this works great for CRM, particularly when working inside different organisations. I can keep my development organisation and all pop ups in one IE instance and my live instance in another. You can find the option to do this under IEToolsInternet Options and click the Settings button under the Tabs section on the General tab.
CRM iPhone homescreen icon
I sometimes like to check up on cases and activities from my iPhone and have a homescreen shortcut to our CRM mobile express site. By default, Dynamics CRM does not have an iPhone icon, so I created one for myself here. If you’d like to use it, download it, save it as apple-touch-icon.png and drop it into your CRM web root folder (mine is c:inetpubwwwroot). When you next navigate to your CRM mobile express site, add it to your homecreen and it will display a much prettier icon.
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"; }
Hide tabs and disable fields based on user roles
The below is a way to hide a tab to everyone not in the Account Manager and System Administrator roles. There’s also a slightly less polished method to disable fields to everyone not in the System Administrator role.
You should be able to copy and paste the below script into your OnLoad event and change the bottom 2 lines of code to specify the tab you want to hide. It wil then hide it from everyone not in the roles specified. You’ll also have to change the attribute names which you want to disable in the HideField function.
Changing an Active Directory username in CRM
To get around it, I made the change directly in the organisation database. The domain login name is stored in the ‘DomainName’ column of the ‘SystemUserBase’ table, so I just edited the data within SQL management studio.
FYI – Although I do this, I don’t recommend making any changes to the CRM databases directly. A safer workaround is posted here
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!