Most Used JavaScript Syntax used in MS CRM

In this blog we will see how we can retrieve different data types fields values in MS CRM using JavaScript.

Different types of data types in MS CRM:

  • Single Line of Text
  • Option Set (Dropdown)
  • Two Options (Radio Button)
  • Image
  • Whole Number
  • Floating Point Number
  • Decimal Number
  • Currency
  • Multiple Lines of Text
  • Date and Time
  • Lookup

 Single or Multiline Field : 
var name = formContext.getAttribute("new_name").getValue(); 
formContext.getAttribute("new_name").setValue();
Option-Set Field : 
int value = formContext.getAttribute("new_type").getValue();
var optionsetText = formContext.getAttribute("new_type").getText();

formContext.getAttribute("new_type").setValue(100); //100 will be the optionset value
Multi-Select Option-Set Field : 
var multiselectValueArr = formContext.getAttribute("new_multiselect").getValue();
formContext.getAttribute("new_multiselect").setValue([100, 200, 300]);
Two-Option Field : 
var value = formContext.getAttribute("new_twooption").getValue(); //will return true or false
formContext.getAttribute("new_twooption").setValue(true);
Whole Number or Floating Number or Currency Field : 
var value = formContext.getAttribute("new_number").getValue();
formContext.getAttribute("new_number").setValue(22);
Date Field : 
var date = formContext.getAttributre("new_date").getValue();
formContext.getAttribute("new_date").setValue("03/03/2022"); date format should be dd/mm/yyyy
Lookup Field : 
var lookup = new Array();
lookup[0] = new Object();
lookup[0].Id = GuidOfRecord;
lookup[0].name = nameOfRecord;
lookup[0].entityType = schemaOfEntity;
formContext.getAttribute("new_lookupfield").setValue(lookup);

var lookupValue = formContext.getAttribute("new_lookupfield").getValue();
var id = lookupValue[0].Id;
var name = lookupValue[0].name;
var entityName = lookupValue[0].entityType;

Comments

Popular posts from this blog

Accessing Fields on QuickView Form through javaScript

ADF - (Part 2) Integrate Data From CRM to External system

ADF - (Part3) Integrate Data From CRM to External system Using Stored procedure