Changing Microsoft CRM Dynamics 4.0 Encoding
Recently I worked on a project involving Microsoft CRM Dynamics 4.0 and because the application was in french we decided to change the encoding from UTF-8 to ISO-8859-1 which is quite simple to do but we ended up with a lot of problems...
If you change the encoding of the CRM in the web.config (globalization tag), CRM will then start to show you weird things (horrible characters) instead of accents. The reason is simple, if you convert a text (containing accents) from an encoding like ISO-8859-1 (or Windows-1252) to URF-8 all the accents will be replaced with fucked up characters, leaving normal non-accentuated characters intact.
I discovered that CRM seems to have parts that are always running under UTF-8 instead of following the encoding in the web.config file, so this cause a constant-encoding-converting-glitch. I did not found a solution to solve those CRM glitches so I decided to come back to default CRM encoding: UTF-8.
Beeing in UTF-8 causes convertion problems to the files I add to the CRM (.js - JavaScript). Because my files I create are in Windows-1252 (default), when CRM flush them to the client, they get "converted" and so the accents are beeing mashed up, this causing IE to not load those .js files. The only solution for this is to manualy change the encoding of the .js files to UTF-8 so that they don't get converted automatically.
Conclusion
Never change the CRM encoding; let it to UTF-8 and adapt your stuff.
Microsoft Dynamics CRM 4.0 tabSet list
As I explained in another article, when you want to retrieve to name of the entity displayed in a CRM page it's easy to check for the etc parameter and then translate the number to a name by calling the MetaData service. But, as I also said, when you check for the page "areas.aspx", you don't have the entity number of the related entity... instead you get a tabSet parameter. The tabSet contains either the relationship name or a tabSet name...
Because the same related entity can have multiple tabSet names, I decided to list everything I found to simplify the job for you (I all got those using Fiddler and clicking on every link of related entities in CRM...).
| Area name |
Related entity name |
| areaActivities |
ActivityPointer |
| areaActivityHistory |
ActivityPointer |
| areaAsyncOperations |
WFProcess |
| areaRelationships |
CustomerRelationship |
| areaRelationship |
CustomerRelationship |
| areaContacts |
Contact |
| areaSubConts |
Contact |
| areaSubAccts |
Account |
| areaAddresses |
CustomerAddress |
| areaOpps |
Opportunity |
| areaOpportunities |
Opportunity |
| areaQuotes |
Quote |
| areaOrders |
SalesOrder |
| areaInvoices |
Invoice |
| areaService |
Incident |
| areaCases |
Incident |
| areaContract |
Contract |
| areaListsInSFA |
List |
| areaCampaignsInSFA |
Campaign |
| areaProducts |
Product |
| areaSubs |
Product |
| areaComp |
Competitor |
| areaComps |
Competitor |
| areaSalesLit |
SalesLiterature |
| areaItems |
ProductPriceLevel |
| areaContractLines |
ContractDetail |
| areaRoles |
Role |
| areaTeams |
Team |
| areaServices |
Service |
| areaResourceGroup |
ResourceGroup |
| areaResourceGroups |
ResourceGroup |
| areaUsers |
SystemUser |
| areaBiz |
BusinessUnit |
| areaResource |
Resource |
| areaUnits |
UoM |
| areaPrices |
ProductPriceLevel |
| areaMembers |
SystemUser |
| areaExistingProducts |
QuoteDetail SalesOrder Invoice |
| areaWriteInProducts |
QuoteDetail SalesOrder Invoice |
All this may save you some hours of clicking !
Retrieving the entity name or number from a CRM page URL
Recently I had to create an HttpModule that catch every call to a CRM page and inject some JavaScript code in it. The first the HttpModule does is to retrieve to entity name (or number) and instanciates a class that contains some information about the page (organization, page url, entity name, entity number, etc...). Normally it is easy, you can get the etc querystring parameter to get the number and then call the MetaData service to get the entity name. Sometimes the querystring parameter gets another name... it's not always etc: it can be "etc", "oType" or "iObjType".
Life will be too easy if everytime when want to get the entity number we just have to check for the querystring parameter... so Microsoft though about a more challenging way to get the entity number. You will face that if you catch the "areas.aspx" page. This page is the one that is called when you click a left navigation bar item (in an entity record).
Let's check some different URLs you can get in CRM :
For the entity form...
...of CRM entities
- http://crmserver/org/sfa/accts/edit.aspx (Account)
- http://crmserver/org/sfa/conts/edit.aspx (Contact)
- http://crmserver/org/activities/email/edit.aspx (Email activity)
...of user-defined entities
- http://crmserver/org/userdefined/edit.aspx?etc=#entity_number#
These looks very easy to understand and it's easy to retrieve the entity numer or name. You will have to hard-code the entity number or name in your code when you get CRM entities because the URL (page) tells which entity it is. For the user-defined, you simply get the "etc" parameter in the QueryString.
For the entity record list...
...of the activites, campains and cases
- http://crmserver/org/workplace/home_activities.aspx
- http://crmserver/org/ma/home_camps.aspx
- http://crmserver/org/cs/home_cases.aspx
...of anything else
- http://crmserver/org/_root/homepage.aspx?etc=#entity_number#
These looks also very easy to understand but you will notice that barely everything (including user-defined entities) are shown in the same page (homepage.aspx) so you will not have to hard-code a lot of thing. And now, for the entity relationship view (the one you get on the right side of the CRM entity form when you click on a left navigation bar item of the entity form)...
...of CRM entities
- http://crmserver/org/sfa/accts/areas.aspx?oId=[GUID]&oType=1&security=[number]&tabSet=areaContacts (Account showing related contacts)
...of user-defined entities (one-to-many relationship)
- http://crmserver/org/sfa/accts/areas.aspx?oId=[GUID]&oType=1&security=[number]&tabSet=account_new_myentityname (Account showing related new_myentityname)
...of user-defined entities (many-to-many relationship)
- http://crmserver/org/sfa/accts/areas.aspx?oId=[GUID]&oType=1&security=[number]&tabSet=areaaccount_new_myentityname (Account showing related new_myentityname)
This not sound very cool... the same querystring parameter (tabSet) can contains 3 different types of value... depending on whether the related entity is custom or built-in and if it is a one-to-many or many-to-many relationship... !
More horrible than this, for the same related entity (shown in different parent entity), the tabSet parameter will not be named the same way (but sometimes it is...). For example, if the related entity is a contact, the tabSet can be named "areaContacts" or "areaSubConts". Wow ! I don't have to tell you it has to be a lot hard-coded !
For the user-defined entities it is a lot more simple than this; the value in the tabSet is the relationship name. This is cool because you can query the CRM MetaData service and get both entities of the relationship. There's only a little twist with this... when you have a many-to-many relationship, the tabSet starts with "area"... I don't know why but MS decided to do it this way so we have to deal with it.
Because the tabSet parameter is a pain, I decided to write an article listing all the different tabSet values I've found in hour of clicking in CRM (because I didn't find it on the web).
JavaScript AJAX wrapper for CRM 4.0
If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.
I'm currently working on a big development project involving CRM.
This class is a clean wrapper for all your AJAX calls.
JavaScript AJAX wrapper for CRM 4.0
function AjaxWrapper()
{
var object = this;
object.Request = NewRequest();
object.Request.onreadystatechange = CompleteRequest;
this.Sync = true;
this.Method = "GET";
this.URL = "";
this.WebServiceMethod = "";
this.Parameters = new ParameterCollection();
this.Execute = ExecuteRequest;
this.AsyncCallbackMethod = null;
this.ResultXML = null;
this.ResultText = null;
function NewRequest()
{
if (window.XMLHttpRequest)
return new XMLHttpRequest();
else
return new ActiveXObject("Microsoft.XMLHTTP");
}
function ExecuteRequest()
{
var parameters = object.Parameters.toString();
ResetRequest();
if (this.Method.toUpperCase() == "POST")
{
if (object.WebServiceMethod.length > 0)
object.Request.open(object.Method, object.URL + "/" + object.WebServiceMethod, !object.Sync);
else
object.Request.open(object.Method, object.URL, !object.Sync);
object.Request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
object.Request.send(object.Parameters);
}
else if (this.Method.toUpperCase() == "GET")
{
if (object.WebServiceMethod.length > 0 && parameters.length > 0)
object.Request.open(object.Method, object.URL + "/" + object.WebServiceMethod + "?" + parameters, !object.Sync);
else if (object.WebServiceMethod.length > 0)
object.Request.open(object.Method, object.URL + "/" + object.WebServiceMethod, !object.Sync);
else if (parametres.length > 0)
object.Request.open(object.Method, object.URL + "?" + parameters, !object.Sync);
else
object.Request.open(object.Method, object.URL, !object.Sync);
object.Request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
object.Request.send();
}
else
{
throw "The method '" + this.Method.toUpperCase() + "' is not supported !";
}
if (object.Sync)
FinishRequest(object.Request.responseText);
}
function CompleteRequest()
{
if (object.Request.readyState == 4)
{
if (object.Request.status == 200)
{
FinishRequest(object.Request.responseText);
if (object.AsyncCallbackMethod != null)
object.AsyncCallbackMethod();
}
}
}
function ResetRequest()
{
object.Request = NewRequest();
object.Request.onreadystatechange = CompleteRequest;
}
function FinishRequest(retourTexte)
{
var xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
object.ResultText = object.Request.responseText;
try
{
xmlDoc.loadXML(object.Request.responseText);
if (xmlDoc.parsed && xmlDoc.xml.length > 0)
object.ResultXML = xmlDoc;
else
object.ResultXML = null;
}
catch (ex)
{
object.ResultXML = null;
}
}
}
The ParameterCollection to help adding QueryString parameters safely (well-encoded values)
function ParameterCollection()
{
this._list = new Array();
this.Add = function (name, value)
{
this._list[this._list.length] = new Array(name, value);
}
this.toString = function ()
{
var queryString = "";
for (var i=0; i<this._list.length; i++)
{
if (queryString.length > 0)
queryString = queryString + "&";
queryString = queryString + this._list[i][0] + "=" + encodeURIComponent(this._list[i][1]);
}
return queryString;
}
}
Hide and show items in a picklist in CRM 4.0
If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.
I'm currently working on a big development project involving CRM.
Those methods seems a lot more complicated than they has to be because we can't really hide and show items in picklists (HTML select). In HTML if you want to hide an "option" of a select, you need to remove it ! So when you want to show it back again you need to readd it to the list, and in addition to that, it will be placed at the end, not where he was before... so I created methods to help people to really hide and show CRM picklist items only by their value.
Hide a picklist item in CRM 4.0
function HidePickListItem(listID, value)
{
var objList = document.getElementById(listID);
// If the list has never been saved, save it now
if (objList.SavedList == null)
{
var arrListe = new Array();
for (var i=0; i<objList.options.length; i++)
{
arrListe[i] = new Object();
arrListe[i].value = objList.options[i].value;
arrListe[i].Libelle = objList.options[i].text;
arrListe[i].Visible = true;
}
objList.SavedList = arrListe;
}
for (var i=0; i<objList.SavedList.length; i++)
if (objList.SavedList[i].value == value)
objList.SavedList[i].Visible = false;
for (var i=objList.options.length - 1; i>=0; i--)
if (objList.options[i].value == value)
objList.options.remove(i);
}
Show a picklist item that has been hidden in CRM 4.0
function ShowPickListItem(listID, value)
{
var objList = document.getElementById(listID);
if (objList.SavedList !=
null)
{
var selValue =
null;
var indexInsertion = 0;
for (
var i=0; i<objList.SavedList.length; i++)
if (objList.SavedList[i].value == value)
objList.SavedList[i].Visible =
true;
// Keep the selected value so we can reselect it after
if (objList.selectedIndex > -1)
selValue = objList.options[objList.selectedIndex].value;
// Remove all the items in the list
for (var i=objList.options.length - 1; i>=0; i--)
objList.options.remove(i);
// Add the items that must be visible
for (var i=0; i<objList.SavedList.length; i++)
{
if (objList.SavedList[i].Visible)
{
var oOption = document.createElement('option');
oOption.text = objList.SavedList[i].Libelle;
oOption.value = objList.SavedList[i].value;
objList.options.add(oOption);
}
}
// Reselect the item that was selected
for (var i=0; i<objList.options.length; i++)
if (objList.options[i].value == selValue)
objList.selectedIndex = i;
}
}
Maximize the CRM child windows
If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.
I'm currently working on a big development project involving CRM. One of the client need was that all the windows appear fullscreen because their users are not familiar with mutliple levels of pop-up so by maximizing every window, you always have the feeling to be in the same window.
Maximize the window in CRM 4.0
function MaximizeWindow()
{
window.moveTo(0, 0);
window.resizeTo(screen.width, screen.height);
}
How to get selected items in a CRM grid in CRM 4.0
If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.
I'm currently working on a big development project involving CRM.
Get the selected items in a CRM grid in CRM 4.0
With this function you get only the GUIDs of the records selected.
function GetSelectedItemsInGrid()
{
return getSelected("crmGrid");
}
How to hide and show left navigation items in CRM 4.0
If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.
I'm currently working on a big development project involving CRM.
The first you need to do when you want to manipulate the left navigation section is to create a general function to get a reference to a navigation block. The reason is because each time you want to hide or show a block or nav item you need the DOM reference of the navigation block so instead of copying the code every time, you write a function and you call it everywhere.
Get the DOM reference to a left navigation block in CRM 4.0
function GetNavBlock(block)
{
var objBlockDetails = document.getElementById("_NA_Info");
var objBlockSales = document.getElementById("_NA_SFA");
var objBlockService = document.getElementById("_NA_CS");
var objBlockMarketing = document.getElementById("_NA_MA");
var objNavBlock = null;
if (objBlockDetails.innerText.substr(0, objBlockDetails.innerText.indexOf(":")).toLowerCase() == block.toLowerCase())
objNavBlock = objBlockDetails;
else if (objBlockSales.innerText.substr(0, objBlockSales.innerText.indexOf(":")).toLowerCase() == block.toLowerCase())
objNavBlock = objBlockSales;
else if (objBlockService.innerText.substr(0, objBlockService.innerText.indexOf(":")).toLowerCase() == block.toLowerCase())
objNavBlock = objBlockService;
else if (objBlockMarketing.innerText.substr(0, objBlockMarketing.innerText.indexOf(":")).toLowerCase() == block.toLowerCase())
objNavBlock = objBlockMarketing;
else
throw "The navigation block '" + block + "' doesn't exists.";
return objNavBlock;
}
Hide a navigation block in CRM 4.0
function HideNavBlock(block)
{
var objNavBlock = GetNavBlock(block);
objNavBlock.parentElement.style.display = "none";
}
Show a navigation block in CRM 4.0
function ShowNavBlock(block)
{
var objNavBlock = GetNavBlock(block);
objNavBlock.parentElement.style.display = "";
}
Hide a navigation item in a navigation block in CRM 4.0
function HideNavItem(block, item)
{
var objNavBlock = GetNavBlock(block);
for (var i=0; i<objNavBlock.nextSibling.childNodes.length; i++)
{
var menuItem = objNavBlock.nextSibling.childNodes[i];
if (menuItem.childNodes[0].childNodes[1].innerText == item)
menuItem.style.display = "none";
}
}
Show a navigation item in a navigation block in CRM 4.0
function ShowNavItem(block, item)
{
var objNavBlock = GetNavBlock(block);
for (var i=0; i<objNavBlock.nextSibling.childNodes.length; i++)
{
var menuItem = objNavBlock.nextSibling.childNodes[i];
if (menuItem.childNodes[0].childNodes[1].innerText == item)
menuItem.style.display = "";
}
}
How to hide, show and select tabs in CRM 4.0
If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.
I'm currently working on a big development project involving CRM.
Hide a tab in CRM 4.0
function HideTab(tabNumber)
{
var tab = document.getElementById("tab" + (tabNumber - 1).toString() + "Tab");
tab.style.display = "none";
}
Show a tab in CRM 4.0
function ShowTab(tabNumber)
{
var tab = document.getElementById("tab" + (tabNumber - 1).toString() + "Tab");
tab.style.display = "";
}
Select a tab in CRM 4.0
function SelectTab(tabNumber)
{
var tab = document.getElementById("tab" + (tabNumber - 1).toString() + "Tab");
tab.click();
}
How to hide and show sections in CRM 4.0
If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.
I'm currently working on a big development project involving CRM.
Hide a section in a tab in CRM 4.0
function HideSection(tabNumber, sectionNumber)
{
var tab = document.getElementById("tab" + (tabNumber - 1).toString());
tab.childNodes[0].rows[(sectionNumber - 1).toString()].style.display = "none";
}
Show a section in a tab in CRM 4.0
function ShowSection(tabNumber, sectionNumber)
{
var tab = document.getElementById("tab" + (tabNumber - 1).toString());
tab.childNodes[0].rows[(sectionNumber - 1).toString()].style.display = "";
}