Tuesday, November 26, 2013

MSCRM 2011 : Enabling and Disabling the Attribute using Java script

MSCRM 2011 : Enabling and Disabling the Attribute using Java script

To Disable
Xrm.Page.ui.controls.get("new_customer").setDisabled(true);

To Enable
Xrm.Page.ui.controls.get("new_customer").setDisabled(false);

Hope this will help :)

Best Regards,
Sreenath

MSCRM : Checking the Checkbox is checked or not using Java script

MSCRM 2011 : Checking the Checkbox is checked or not using Java script

var useexistingcheckbox = "checkboxAttributeName";

var ckeckboxControl = Xrm.Page.ui.controls.get(useexistingcheckbox);

var ckeckboxControlValue = ckeckboxControl.getAttribute().getValue();

if (ckeckboxControlValue == true)
{
   //Code
}
else
{
   //Code
}

Hope This will Help :)

Best Regards,
Sreenath

Monday, November 25, 2013

MSCRM : Change background color of Attribute using Javascript

MSCRM 2011: Change background color of Attribute using JavaScript

Use the following code:

document.getElementById("AttributeName").style.backgroundColor = "#FFFF99";

Hope this will help :)

Best Regards,
Sreenath

MSCRM : Setting value for a Attribute using Java Script

MSCRM 2011 : Setting value for a Attribute using Java Script

Use the following code.

Xrm.Page.getAttribute("AttributeName").setValue("AttributeValue");

Hope this will Help :)

Best Regards,
Sreenath M

MSCRM : Filtering Lookups using Javascript

MSCRM 2011: Filtering Cities based on State


Use the following code to filter and change the Entity names according to your requirement.

function onstateChange()
{
  var stateAttr = Xrm.Page.data.entity.attributes.get("new_state");
  if (stateAttr.getValue() != null)
  {
    var stateID = stateAttr.getValue()[0].id;
    var viewID = stateID;
    var viewDisplayName = "Filtered by state - " + stateAttr.getValue()[0].name;
    var viewIsDefault = true;

    var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical"   distinct="false"><entity name="new_city"><attribute name="new_cityid"/><attribute name="new_name"/><attribute name="createdon"/><order attribute="new_name" descending="false"/><filter type="and"><condition attribute="new_state" operator="eq" value="' + stateID + '"/></filter></entity></fetch>';

var layoutXml = '<grid name="resultset" object="10001" jump="new_name" select="1" icon="1" preview="1"><row name="result" id="new_cityid"><cell name="new_name" width="300" /><cell name="createdon" width="125"/></row></grid>';

var phaseControl = Xrm.Page.ui.controls.get("new_city");
phaseControl.addCustomView(viewID, "new_city", viewDisplayName, fetchXml, layoutXml, viewIsDefault);
   }
}

Hope this will help :)

Best Regards,
Sreenath

Making Entity Attribute as required through Java Script

CRM 2011: In Java Script Web resource please add the below code.

Xrm.Page.getAttribute("AttributeName").setRequiredLevel("required");

Hope this Will Help :)

Regards,
Sreenath