Hide and Show Section Using Java Script in CRM

In this article , I am going to explain how to hide sections

Hiding Section


Showing Section


MS CRM - Get Lookup Value Using Java Script

: suppose you have a lookup on your form and you would like get information like ID,Name,Entity Type of the record(s) which the lookup is set to.


lookupItem = Xrm.Page.getAttribute(“LookypAttributeSchemaName“).getValue();
var name = lookupItem[0].name;
var guid = lookupItem[0].id;
var entitytype = lookupItem[0].entityType;

MS CRM - Set Lookup Using Java Script

Brief: you have a lookyup on your form and you would like to set it regarding specific record in a

specific  entity (for ex : Account or Contact ) .


Xrm.Page.getAttribute(“LookypAttributeSchemaName“).setValue( [{id: idValue, name: textValue, entityType: typeValue}]);
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id =YourID;
lookupValue[0].name =YourName ;
lookupValue[0].entityType =YourEntityType ;

MS CRM - Set Option Set by Text or Value Using Java Script

Brief :

Consider having an option set on a Dynamics CRM 2011/2013/2015 form and you want
to change the selected item or it have no selected item currently and you would like to set it.

You have to 2 ways to do it.

  • By Value


  • By Text

    Actually you can't set the selected item by text by you can search all options untill you find the on whose text (label) is the same as one the one you have then get its value

    setOptionSetByOptionText = function(optionsetAttribute, optionText)

    var options = Xrm.Page.getAttribute(optionsetAttribute).getOptions();

    for(i = 0; i < options.length; i++)
    if (options[i].text == optionText)



    ExamplesetOptionSetByOptionText ("new_nationality","American");

MS CRM - Get Option Set Value and Label using java script

Brief: Suppose that you have an option set on a Dynamics CRM 2011 Form and you would like

to get the value and & the label of the selected item.

  • To get label 


  • To get value