Hide and Show Section Using Java Script in CRM

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

Hiding Section

-Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex).setVisible(false);
-Xrm.Page.ui.tabs.get(tabIndex).sections.get("sectionName").setVisible(false);

Showing Section

-Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex).setVisible(true);
-Xrm.Page.ui.tabs.get(tabIndex).sections.get("sectionName").setVisible(true);

MS CRM - Get Lookup Value Using Java Script


Brief
: 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.

Code

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 ) .

Code:

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

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

    Xrm.Page.getAttribute("optionsetAttribute").setValue(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)
    Xrm.Page.getAttribute(optionsetAttribute).setValue(options[i].value);
    }

    }

     

    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 

Xrm.Page.getAttribute("OptionSetSchemaName").getText();

  • To get value 

Xrm.Page.getAttribute("OptionSetSchemaName").getValue();