Tuesday 22 May 2012

Serial No Generation Jscript CRM 2011

function Form_onload()
{
function PadDigits(data, totalDigits, padChar)
{
     data = data.toString();
     var pad = '';
     var dataLen = data.length;
     if (totalDigits > dataLen)
     {
          for (i=0; i < (totalDigits-dataLen); i++)
         {
             pad += padChar;
         }
     }
     return pad + data.toString();
}
Xrm.Page.getAttribute("numberlength").getValue()=8;
if (Xrm.Page.ui.getFormType() == 2)
{
if (Xrm.Page.getAttribute("currentnumber").getValue() == null)
{
Xrm.Page.getAttribute("currentnumber").getValue()=1000;
}
var prefix = Xrm.Page.getAttribute("prefix").getValue();
var separator = Xrm.Page.getAttribute("separator").getValue();
var currentno = Xrm.Page.getAttribute("currentnumber").getValue();
var serialno = prefix + separator + PadDigits(currentno,8,"0");
Xrm.Page.getAttribute("previewserialnumber").getValue()=serialno;
}
}

If the field is null, se the field value to 1000 (JavaScript)


if (Xrm.Page.getAttribute("currentnumber").getValue() == null)
{
Xrm.Page.getAttribute("currentnumber").getValue()=1000;
}

Is there a way within CRM 2011 of limiting access to a system dashboard or a system view to a specific security role?  In the same way we do with CRM forms.

One thing you can do is....
1. Create a system dashboard but  set the DBrd's  Tab(s) component  property visibility to 'False'
This results in a blank page when anyone looks at it

2. You (or anyone that has rights to create a dashboard) can then make a personal Save As copy of the system dashboard (reset the Tab visibility) and share with the appropriate team
(downside loads of Qs re blank system dashboards )

(If System dashboard's are imported/exported in a solution you can even delete them once the personal DashBoards have been created - personal dashboards cant be packaged into a solution)

Monday 21 May 2012


JavsaScript to set the charging costs for application Fee by charging band CRM 2011

function new_chargingband_onchange()

if (Xrm.Page.getAttribute("new_chargingband").getValue() == null)
{
Xrm.Page.getAttribute("new_applicationfee").getValue()=null;
Xrm.Page.getAttribute("new_applicationfee").setSubmitMode("always");
}
{
if (Xrm.Page.getAttribute("new_chargingband").getSelectedOption().text !=null)
{
switch (crmForm.new_chargingband.getSelectedOption().text)
{
case "Micro":
Xrm.Page.getAttribute("new_applicationfee").setValue(400);
Xrm.Page.getAttribute("new_applicationfee").setSubmitMode("always");
break
case "Small":
Xrm.Page.getAttribute("new_applicationfee").setValue(800);
Xrm.Page.getAttribute("cf_applicationfee").setSubmitMode("always");
break
case "Medium":
Xrm.Page.getAttribute("new_applicationfee").setValue(1600);
Xrm.Page.getAttribute("new_applicationfee").setSubmitMode("always");
break
case "Large":
Xrm.Page.getAttribute("new_applicationfee").setValue(2400);
Xrm.Page.getAttribute("new_applicationfee").setSubmitMode("always");
break;
}
}
}
}

Dynamic Picklist for case type and sub type CRM 4.0 and 2011


var otestpick_parent = Xrm.Page.getAttribute("new_casetypecode");

var iStartIndex = -1;
var iEndIndex = -1;

switch (otestpick_parent.getSelectedOption().text)
{
case "XYZ":
iStartIndex = 1;
iEndIndex = 10;
break;

}

var otestpick_child = Xrm.Page.getAttribute("new_casesubtype");

//added to fix

var currentValue = otestpick_child.getValue();

if (iStartIndex > -1 && iEndIndex > -1)
{
var oTempArray = new Array();
var iIndex = 0;
for (var i = iStartIndex; i <= iEndIndex; i++)
{
oTempArray[iIndex] = otestpick_child.originalPicklistOptions[i];
iIndex++;
}
otestpick_child.Options = oTempArray;
//added to fix
                   otestpick_child.setValue(currentValue);
otestpick_child.Disabled = false;
}
else
{
otestpick_child.setValue(null);
otestpick_child.Disabled = true;
}


JavaScript script to autopopulate the case title field CRM 2011

Autopopulating of Case title On Save depending on casetypecode, casesubtype, systemorganisation


if ((Xrm.Page.ui.getFormType() == 2)||(Xrm.Page.ui.getFormType() == 1)||(Xrm.Page.ui.getFormType() == 5)||(Xrm.Page.ui.getFormType() == 6))
{
var part1 = Xrm.Page.getAttribute("casetypecode").getSelectedOption().text;
var part2 = Xrm.Page.getAttribute("casesubtype").getSelectedOption().text;
var part3 = Xrm.Page.getAttribute("systemorganisation").getValue();
var part4 = (part1+' - ' + part2 +' - ' + part3);
Xrm.Page.getAttribute("title").setValue(part4);
Xrm.Page.getAttribute("title").setSubmitMode("always");
}

Mobile number validation using regex CRM 2011

function validateMobile(context){

var mobi =context.getEventSource().getValue();
mobiRegex = /^(083|084|085|086|087|088|089)\s?\d{3}\s?\d{4,5}$/;
if(!mobi.match(mobiRegex)){

   event.returnValue = false;
   alert("The format of the mobile no is incorrect") ;
   }

}