Tuesday, July 31, 2012

MSCRM 4.0 Remove new record

Microsoft Dynamics CRM 4.0 Removing new record button from the standard Tool Bar.
It is unsupported!
1) Go to the web site server
2) Open {MSCRM folder}/_root/bar_Top.aspx with any text editor
3) Find first script tag
It should look like this:

<script type="text/javascript">

function DownloadClient()
{
var sUrl = "/_root/ClientInstaller.exe";
var oFrame = window.document.frames.frmDownloadOlk;
if(IsNull(oFrame))
{
oFrame = window.document.createElement("<iframe style='display:none' id='frmDownloadOlk' src='" + prependOrgName("/_root/Blank.aspx") + "'></iframe>");
oFrame = window.document.body.insertBefore(oFrame);

window.setTimeout("window.document.frames.frmDownloadOlk.location = \"" + sUrl + "\"", 10);
}
else
{
oFrame.location = sUrl;
}
}
function DisableAddinDownload() {
if (!IsNull(document.getElementById("btn_download_olk")))
{
document.getElementById("btn_download_olk").style.visibility = "hidden";
}
}

</script>
<!--[if MSCRMClient]>
<script  type="text/javascript">
window.attachEvent( "onload", DisableAddinDownload);
</script>

4) Add RemoveNewRecord to the script
function RemoveNewRecord(){
if (!IsNull(document.getElementById("mnu_new_record")))
{
document.getElementById("mnu_new_record").style.display = "none";
}
}

5) Add window.attachEvent( "onload", RemoveNewRecord); to the script

The script should look like this:
<script type="text/javascript">
function DownloadClient()
{
var sUrl = "/_root/ClientInstaller.exe";
var oFrame = window.document.frames.frmDownloadOlk;
if(IsNull(oFrame))
{
oFrame = window.document.createElement("<iframe style='display:none' id='frmDownloadOlk' src='" + prependOrgName("/_root/Blank.aspx") + "'></iframe>");
oFrame = window.document.body.insertBefore(oFrame);

window.setTimeout("window.document.frames.frmDownloadOlk.location = \"" + sUrl + "\"", 10);
}
else
{
oFrame.location = sUrl;
}
}
function DisableAddinDownload() {
if (!IsNull(document.getElementById("btn_download_olk")))
{
document.getElementById("btn_download_olk").style.visibility = "hidden";
}
}

function RemoveNewRecord(){
if (!IsNull(document.getElementById("mnu_new_record")))
{
document.getElementById("mnu_new_record").style.display = "none";
}
}
</script>
<!--[if MSCRMClient]>
<script  type="text/javascript">
window.attachEvent( "onload", DisableAddinDownload);
window.attachEvent( "onload", RemoveNewRecord);
</script>

Save and open your MSCRM.

The result should look like:

Thanks for
http://blogs.msdn.com/b/rextang/archive/2008/08/28/8900674.aspx

Wednesday, July 4, 2012

Microsoft Dynamics CRM 2011 Validate required form javascript

Microsoft Dynamics CRM 2011 Validate required form javascript.

This code checks if form is valid for saving, by going over all required attributes and checking if it contains value.


function IsFormValidForSaving(){
var valid = true;
Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
   if (attribute.getRequiredLevel() == "required") {
      if(attribute.getValue() == null){
          if(valid){
              var control = attribute.controls.get(0);
              alert(control.getLabel() + " is missing a value");
              control.setFocus();
          }
          valid = false; 
      }
   }
});
return valid;
}
Another option is using crm system function but then it won't be supported.