Adding sort order to the custom entities tab for security roles in MS CRM

HI Guys/Girls!

We are busy with a huge crm implementation and currently have about 200 custom entities.
When we started to look at the security model for the system and it became a nightmare to set the privileges on the security roles as CRM does not sort the custom entities alphabetically.

So what to DO?
We hack!...

How the solution works:
Locate the file called edit.aspx located at:
[drive]Program Files\Microsoft Dynamics CRM\CRMWeb\Biz\Roles\edit.aspx

Between the script tags at the bottom of the page.(As shown below)

var tbl = document.getElementById('tab7').children(0).children(0).children(0).children(0).children(0);
var x = [];
for (var i = 0; i < tbl.rows.length; i++)
x[i] = [tbl.rows[i].cells[0].innerHTML,tbl.rows[i].outerHTML];
var str = x[0][1];
for (var i = 1; i < x.length-1; i++)
for (var j = i+1; j < x.length; j++)
if (x[i][0] > x[j][0]) {
var tmp = x[j];
x[j] = x[i];
x[i] = tmp;

for (var i = 1; i < x.length; i++)
str += x[i][1];
document.getElementById('tab7').children(0).children(0).children(0).children(0).innerHTML = '<TABLE class=ms-crm-Form-Area onmouseover=SetAltText(); ondblclick=ProcessClick(); onclick=ProcessClick(); cellSpacing=0 cellPadding=2>' + str + '</table>';


Copy and paste the code above into the file or download the file here.

And there you go!, a neat sort order for all your custom entities.
The code can be adopted for the other tabs as well just make a back of your edit.aspx file.

This is a unsupported customization!!!!!! so make a copy of the original file first!