8/25/13

Dynamics CRM How to Access Page Controls with JavaScript

When working with Dynamic CRM custom solutions, I often have to implement some UI control behaviors with JavaScript.  The table below shows some of the common tasks that can be done when using the XRM JavaScript framework that comes with the Dynamics platform.

Task
XRM JavaScript Framework API
Show or Hide a control
setVisible(cmd)

cmd bool  value:  
true  to show
false to hide

Disable or enable a control
setDisabled(cmd)

cmd bool  value:
true = to disable
false to enable
Focus
setFocus()

This table shows the steps to access a control and set several properties:

Tasks
Script
Get a control reference
var control = Xrm.Page.getControl(name.toLowerCase());

Note:  Controls on the web form are set with lowercase letters.

Disable a control
control.setDisabled(true);

Enable a control
control.setDisabled(false);

Show a control
control.setVisible(true);

Hide a control
control.setVisible(false);

Set the focus
control.setFocus();



I hope you enjoy this quick reference.