Dynamics CRM JavaScript - Get Value Method

 Hi Friends,

 
In this blog, we learn about Dynamics CRM FormContext Javascript. 
 
Below we have a list of Dynamics CRM Field DataTypes.
 
Out-of-the-box, CRM provides 12 types of data fields that can be placed on forms :
  1. Single Line of Text
  2. Option Set (Dropdown)
  3. Two Options (Yes/No)
  4. Whole Number
  5. Floating Point Number
  6. Decimal Number
  7. Currency
  8. Multiple Lines of Text
  9. MultiSelect option Set
  10. Date and Time
  11. Lookup
  12. Customer
Two Methods in formcontext Javascript :
  1. Get Value
  2. Set Value 
 1. Get Value Method 
 
1. Single Line of text
 
function gettext(executionContext)
{
 
var formContext = executionContext.getFormContext();
 
var textvalue = formContext.getAttribute("crf6b_name").getValue(); 
 
Xrm.Utility.alertDialog(textvalue);
  
}
 
Note: "crf6b_name" filed schema name
 
2..Get OptionSet(Dropdown)
 
function getoptionset(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var getoptnvalue = formContext.getAttribute("crf6b_gender").getValue();
 
Xrm.Utility.alertDialog(getoptnvalue);
 
}
 
Note:"crf6b_gender" filed schema name
 
3.Two Options (Yes/No)
 
function getoptionset(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var twooptnvalue = formContext.getAttribute("crf6b_experienceind365").getValue();
 
Xrm.Utility.alertDialog(twooptnvalue);
 
}
 
Note:"crf6b_experienceind365" filed schema name 
  
 
4.Whole Number
 
function getwholenumber(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var wholenumber= formContext.getAttribute("crf6b_wholenumber").getValue();
 
Xrm.Utility.alertDialog(wholenumber);
 
}
 
 Note:"crf6b_wholenumber" filed schema name  
 
5.Floating Point Number
 
function getfloatnumber(executionContext)
{
 
var formContext = executionContext.getFormContext();
 
var floatnumber= formContext.getAttribute("crf6b_floatnumber").getValue();
 
Xrm.Utility.alertDialog(floatnumber);
 
}
 
Note:"crf6b_floatnumber" filed schema name  
 
6.Decimal Number
 
function getdecimalnumber(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var decimalnumber= formContext.getAttribute("crf6b_decimalnumber").getValue();
 
Xrm.Utility.alertDialog(decimalnumber);
 
}
 
Note:"crf6b_decimalnumber" filed schema name  
 
 
7.Currency
 
function getcurrencynumber(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var currencynumber= formContext.getAttribute("crf6b_currency").getValue();
 
Xrm.Utility.alertDialog(currencynumber);
 
}
 
Note:"crf6b_currency" filed schema name    
 
 
8. Multiple Lines of Text
 
function getmultiline(executionContext)
{
 
var formContext = executionContext.getFormContext();
 
var multiline= formContext.getAttribute("crf6b_multiline").getValue();
 
Xrm.Utility.alertDialog(multiline);
 
}
 
Note:"crf6b_multiline" filed schema name


9.MultiSelect option Set 

function getmultioptn(executionContext)
{
    var formContext = executionContext.getFormContext();

  var getmultioption =  formContext.getAttribute("cr578_mulipleoptn").getValue();

   Xrm.Utility.alertDialog(getmultioption );

}

Note:"cr578_mulipleoptn" filed schema name 




 




Note: Multi Select OptionSet Value
  1. Quality Engineer - 146630000,
  2. Designer -146630001,
  3. Graphic Designer - 146630002.

10. Date and Time
 
i./Get the Date - its shows the date value
 
function getdate(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var getdate = formContext.getAttribute("crf6b_dateofbirth").getValue();
 
Xrm.Utility.alertDialog(getdate);
 
}
 
 
Note:"crf6b_dateofbirth" filed schema name  
 
 
ii.//Get the Date, Month, Year from Date Field Value
 
function getddmmyyy(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var getdate = formContext.getAttribute("crf6b_dateofbirth").getValue();
 
Xrm.Utility.alertDialog(getdate.getFullYear());
 
Xrm.Utility.alertDialog(getdate.getMonth());
 
Xrm.Utility.alertDialog(getdate.getDate());
 
}
 
 
Note:"crf6b_dateofbirth" filed schema name  
 
 
11.Lookup 
 
For lookup We need
  1. Id,
  2. Name,
  3. EntityType.
//Get LookUp Id
 
function getlookupid(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var lookupid = formContext.getAttribute("parentaccountid").getValue()[0].id;
 
Xrm.Utility.alertDialog(lookupid); 
 
}
 
Note:"parentaccountid" filed schema name  
 
//Get Lookup Name
 
function getlookupname(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var lookupname = formContext.getAttribute("parentaccountid").getValue()[0].name;
 
Xrm.Utility.alertDialog(lookupname); 
 
}
 
 
Note:"parentaccountid" filed schema name  
 
//Get the Entity Logical Name
 
function getentitylogicname(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var entitylogicalname = formContext.getAttribute("parentaccountid").getValue()[0].entityType;
 
Xrm.Utility.alertDialog(entitylogicalname); 
 
}
 
 
Note:"parentaccountid" filed schema name  
 
 
//getlookup
 
function getlookup(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var getlookid = formContext.getAttribute("crf6b_accountlookup").getValue()[0].id;
 
var getlookname = formContext.getAttribute("crf6b_accountlookup").getValue()[0].name;
 
var getlookentitytype = formContext.getAttribute("crf6b_accountlookup").getValue()[0].entityType;
 
Xrm.Utility.alertDialog(getlookid);
 
Xrm.Utility.alertDialog(getlookname);
 
Xrm.Utility.alertDialog(getlookentitytype);
 
}
 
 Note:"crf6b_accountlookup" filed schema name
 
 
 "In Dynamics 365, the formContext provides a reference to a form or form item through JavaScript. The formContext is part of executionContext and replaces Xrm.Page which is deprecated in version 9+ of Dynamics 365."
 
 
Thanks For Reading...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Comments

Post a Comment

Popular posts from this blog

Dynamics CRM JavaScript - Set Value Method