{Code Tip} Accessing fields in CRM header and footer using JavaScript

Many a times there is need to access CRM fields in javascript which are present in either header or the footer. Here are snippets to access fields for enable/disable, get/set and control visibility which exist in either header or footer of a CRM form.

Header Field Scripts:

//Set Enabled to True:

Xrm.Page.getControl(‘header_ fieldname’).setDisabled(false);

//Set Enabled to False:

Xrm.Page.getControl(‘header_ fieldname’).setDisabled(true);

//Set Visibility to False:

Xrm.Page.getControl(‘header_ fieldname’).setVisible(false);

//Set Visibility to True:

Xrm.Page.getControl(‘header _ fieldname’).setVisible(true);

//Get Attribute Value in Footer:

Xrm.Page.getControl(‘header _ fieldname’).getAttribute().getValue();

//Set Attribute Value in Footer:

Xrm.Page.getControl(‘header _fieldname’).getAttribute().setValue(VALUE);

Footer Field Scripts:

//Set Visibility to False:

Xrm.Page.getControl(‘footer_ fieldname’).setVisible(false);

//Set Visibility to True:

Xrm.Page.getControl(‘footer_ fieldname’).setVisible(true);

//Get Attribute Value in Footer:

Xrm.Page.getControl(‘footer_ fieldname’).getAttribute().getValue();

//Set Attribute Value in Footer:

Xrm.Page.getControl(‘footer_fieldname’).getAttribute().setValue(VALUE);

Hope it helps and Happy CRMing!


Check this out
About the Author:

clip_image001

Twitter: https://twitter.com/msdynamicsblog
LinkedIn: https://www.linkedin.com/in/deepesh-somani-00296932

Google Play Store:

https://play.google.com/store/apps/details?id=com.dynamicsofdynamicscrm.msdynamicsblog&hl=en

Advertisement

4 thoughts on “{Code Tip} Accessing fields in CRM header and footer using JavaScript

  1. Hi,
    We have added JavaScript where we need to hide Header Status Reason field on Case form through Javascript.
    We have used below code
    var statusReason_header = Xrm.Page.getControl(“header_statuscode”);
    The above code is returning null reference in Interactive service hub. However the above piece of code is working in web client. We have placed Status Reason field on Case form Header.
    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s