Wednesday 2 May 2012

hide a section in dynamic crm 2011


In single line we can hide a section with the java script:

Xrm.Page.ui.tabs.get("tab_name").sections.get("section_name").setVisible(true);

on some conditions:

function RefundHide()
{

var cat = Xrm.Page.getAttribute("new_city").getValue();
var subcat = Xrm.Page.getAttribute("new_state").getValue();
if(cat ==  852700002 && subcat == 852700014)
{
Xrm.Page.ui.tabs.get("general").sections.get("refund").setVisible(true);
}
}


function hide()
{
var type = Xrm.Page.getAttribute("new_city").getValue();
if (type == null)
{
 Xrm.Page.ui.controls.get("new_state").setDisabled(true);
}
}



function SendSMS()
{
Xrm.Page.data.entity.save("save");
}


function PicklistOneOnchange()
{

var optionsetControl = Xrm.Page.ui.controls.get("new_state");
var options = optionsetControl.getAttribute().getOptions();
var type = Xrm.Page.getAttribute("new_city").getValue();
if (type == null)
{
 Xrm.Page.ui.controls.get(" new_state ").setDisabled(true);
}
optionsetControl.clearOptions();

if (type == 852700000)
{
Xrm.Page.ui.controls.get(" new_state ").setDisabled(false);
for (var i = 1; i <7; i++)
 optionsetControl.addOption(options[i]);
}
if (type == 852700001)
{
Xrm.Page.ui.controls.get(" new_state ").setDisabled(false);
for (var i = 7; i < 10; i++)
  optionsetControl.addOption(options[i]);
}

if (type == 852700002)
{
Xrm.Page.ui.controls.get(" new_state ").setDisabled(false);
for (var i = 10; i < 16; i++)
optionsetControl.addOption(options[i]);
}

if (type == 852700003)
{
Xrm.Page.ui.controls.get(" new_state ").setDisabled(false);
for (var i = 16; i < 19; i++)
optionsetControl.addOption(options[i]);
}
}

for some reference:

http://www.powerobjects.com/blog/2011/01/14/crm-2011-useful-javascript-tidbits/

http://crmbusiness.wordpress.com/2011/02/17/crm-2011-javascript-xrm-page-basics/

Setting Field Required (require)

function resolutionstatus()
{
var type = Xrm.Page.getAttribute("new_resolutionstatus").getValue();
if (type == 852700005)
{
Xrm.Page.ui.controls.get("new_rejectreason").setVisible(true);
Xrm.Page.getAttribute("new_rejectreason").setRequiredLevel("required");

}

else
{
Xrm.Page.getAttribute("new_rejectreason").setRequiredLevel("none");
Xrm.Page.ui.controls.get("new_rejectreason").setVisible(false);
}

}



Disable a field:


function hide()
{
var type = Xrm.Page.getAttribute("casetypecode").getValue();
if (type == null)
{
 Xrm.Page.ui.controls.get("new_subcategory").setDisabled(true);
}
}

calculating two fields:

function calculate()
   {
       var val1 = Xrm.Page.entity.attributes.get['new_val1'].getValue();
      var val2 = Xrm.Page.entity.attributes.get['new_val2'].getValue
();
       
      if(val1==null)return;
     if(val2==null)return;
    
      var result = val1 * val2;
     Xrm.Page.entity.attributes.get['new_result'].setValue(result);
 }

http://community.dynamics.com/product/crm/crmtechnical/b/mshelp/archive/2011/03/14/creating-a-calculated-field-in-dynamics-crm2011.aspx 






No comments:

Post a Comment