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") ;
   }

}

Email validation using regex CRM 2011


function validateEmail(context){

var email =context.getEventSource().getValue();
emailRegex =/^(\w+[\-\.])*\w+@(\w+\.)+[A-Za-z]+$/;
if(!email.match(emailRegex)){

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

}

Defaulting a field and setting disabled on the form load; changing a text field value based on the other picklist field value.


function feeevent() {

    var feeattrib = Xrm.Page.getAttribute("new_fee");
    var feecontrl = Xrm.Page.getControl("new_fee");

    feeattrib.setValue("$ 400");
    feecontrl.setDisabled(true);
}

function bandevent() {

    var picklistOne = Xrm.Page.getControl("new_chargingband");
    var picklistOneAttribute = picklistOne.getAttribute();
    var picklistOneSelectedOption = picklistOneAttribute.getSelectedOption();
    var picklistOneSelectedText = "";
    var feecontrl = Xrm.Page.getControl("new_fee");
    var feeattrib = Xrm.Page.getAttribute("new_fee");

    if (picklistOneSelectedOption != null) {
        picklistOneSelectedText = picklistOneSelectedOption.text;
    }

    if (picklistOneSelectedText != null && picklistOneSelectedText != "") {

        if (picklistOneSelectedText == "Micro") {
            feecontrl.setDisabled(false);
            feeattrib.setValue("$ 400");
            feecontrl.setDisabled(true);
        }

        if (picklistOneSelectedText == "Small") {
            feecontrl.setDisabled(false);
            feeattrib.setValue("$ 800");
            feecontrl.setDisabled(true);
        }

        if (picklistOneSelectedText == "Medium") {
            feecontrl.setDisabled(false);
            feeattrib.setValue("$ 1600");
            feecontrl.setDisabled(true);
        }

        if (picklistOneSelectedText == "Large") {
            feecontrl.setDisabled(false);
            feeattrib.setValue("$ 2400");
            feecontrl.setDisabled(true);
        }

    }

}                                                     


Javascript to create dynamic cascading picklists in Microsoft CRM 2011

Changing a picklist field value based on the other picklist field value


function caseandsubcase() {



    var picklistOneName = "new_case13012012"; //name of the first picklist
    var picklistTwoName = "new_subcase13012012"//name of the picklist with dynamic values

    var picklistOne = Xrm.Page.getControl(picklistOneName);
    var picklistOneAttribute = picklistOne.getAttribute();

    var picklistTwo = Xrm.Page.getControl(picklistTwoName);
    var picklistTwoAttribute = picklistTwo.getAttribute();

    var picklistOneSelectedOption = picklistOneAttribute.getSelectedOption();

    var picklistOneSelectedText = "";
    if (picklistOneSelectedOption != null) {
        picklistOneSelectedText = picklistOneSelectedOption.text;
    }

    //This "if" statement stores the original values from the dynamic picklist.
    //Very important if the user hasn't made a selection on the first picklist or if the selection changes
    if (picklistTwo.flag == true) {
        picklistTwo.clearOptions();
        var origOptions = picklistTwo.originalPicklistValues;

        for (var i = origOptions.length - 1; i >= 0; i--) {
            if (origOptions[i].text != "") {
                picklistTwo.addOption(origOptions[i]);
            }
        }
    }
    else {
        picklistTwo.originalPicklistValues = picklistTwoAttribute.getOptions();
        picklistTwo.flag = true;
    }

    if (picklistOneSelectedText != null && picklistOneSelectedText != "") {
        var picklistTwoOptions = picklistTwoAttribute.getOptions();
        for (var i = picklistTwoOptions.length - 1; i >= 0; i--) {

            if (picklistTwoOptions[i].value != null && picklistTwoOptions[i].value != "") {
                var optionText = picklistTwoOptions[i].text;
                var optionValue = picklistTwoOptions[i].value;

                //BEGIN: If the picklist is set to HMO
                if (picklistOneSelectedText == "Family1") {
                    //Remove these values
                    if (optionText == "Son2" || optionText == "Daughter2") {
                        picklistTwo.removeOption(optionValue);
                    }

                }
                //END: HMO Selection

                if (picklistOneSelectedText == "Family2") {
                    //Remove these values
                    if (optionText == "Son1" || optionText == "Daugher1") {
                        picklistTwo.removeOption(optionValue);
                    }

                }
                //END: PPO Selection


            }
        }
    }



JavaScript Error (Object Expected) On load of the Form when migrated CRM 4.0 to CRM 2011

fieldschema_onchange 0() for example sf_employee_onchange0 () [CRM 4.0]

once you migrate your organisation to CRM 2011, The code should be changed to

fieldschema_onchange () for example sf_employee_onchange () [CRM 2011- Just remove 0 ]

This is the syntax change from CRM 4.0 to CRM 2011 which causes Object Expected Error....

Ribbon Customization -Hide ‘Add Existing’ button in Dynamics CRM 2011

How to hide the ‘Add existing’ button on the Contact Associated view on the Account Entity. When you open an Account entity record and click on ‘Contacts’ in the left navigation bar of the entity. you can see’Add New Contact’ and ‘Add Existing Contact’ buttons. 
image
Follow the bellow steps
  1. Create a Solution & Add Contact entity (Add whatever the entity button you want to hide)
  2. Export the solution
  3. Unzip and Edit the Customizations.xml file
  4. Now we need to fine the Id of the ‘Add Existing’,Add New’ Buttons  For this I opened the ‘contactribbon.xml’ which is available under ..\\sdk\samplecode\cs\client\ribbon\exportribbonxml\exportedribbonxml( this location depends on the Sdk installation directory  on the file system)
  5. I found the ids as shown  below from the contactribbon.xml
  6. ContactRibbon
  7. Add  the below code  in the RibbonDiffXML
  8. Replace the <CustomActions /> with 
  9. <CustomActions>
      <HideCustomAction Location="Mscrm.SubGrid.contact.AddExistingAssoc" HideActionId="Mscrm.SubGrid.contact.AddExistingAssoc.HideAction" />
      <HideCustomAction Location="Mscrm.SubGrid.contact.AddExistingStandard" HideActionId="Mscrm.SubGrid.contact.AddExistingStandard.HideAction" />
    
    </CustomActions>
  • Save the file.
  • Replace the customizaions.xml file in your zip solution with this file.
  • Import the solution and publish the changes.
You are done with it!