Dynamics CRM JavaScript - Set 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 Blog Link:


2.Set Value Method 

1. Single Line of text
 
function settesxt(executionContext)

{
 
var formContext = executionContext.getFormContext();
 
var textvalue = formContext.getAttribute("crf6b_name").setValue("Mohamed Umer Farook"); 
 
  
}
 
Note: "crf6b_name" filed schema name

 
2. OptionSet(Dropdown)
 
function setoptionset(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var setoptnvalue = formContext.getAttribute("crf6b_type").setValue(146630001);
 
}
 
Note:"crf6b_type" filed schema name

Note: Option Set Value Examples
  1. Competitor- 146630001
  2. consultant - 146630002
  3. customer - 146630003




 






3.Two Options  (Yes/No) 

Note: (Yes is true)(No is false).
 
function setoptionset(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var twooptnvalue = formContext.getAttribute("crf6b_creditcard").setValue(true);
 
 
}
 
Note:"crf6b_creditcard" filed schema name 



  
 






4.Whole Number
 
function setwholenumber(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var wholenumber= formContext.getAttribute("crf6b_wholenumber").setValue(1234556778);
 
}
 
Note::"crf6b_wholenumber" filed schema name  

 
5.Floating Point Number
 
function setfloatnumber(executionContext)

{
 
var formContext = executionContext.getFormContext();
 
var floatnumber= formContext.getAttribute("crf6b_floatnumber").setValue(100.3);
 
}
 
Note::"crf6b_floatnumber" filed schema name  

 
6.Decimal Number
 
function setdecimalnumber(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var decimalnumber= formContext.getAttribute("crf6b_decimalnumber").setValue(1.01);
 
}
 
Note:"crf6b_decimalnumber" filed schema name  

Note: If the Precision value is 1 the decimal number value is (1.01).



 
 






7.Currency
 
function setcurrencynumber(executionContext)
 
{
 
var formContext = executionContext.getFormContext();
 
var currencynumber= formContext.getAttribute("crf6b_currency").setValue(102005);
 
}
 
Note:"crf6b_currency" filed schema name    





 



Note: This setting supports values between 0 and 4. 


8. Multiple Lines of Text
 
function setmultiline(executionContext)
{
 
var formContext = executionContext.getFormContext();
 
var multiline= formContext.getAttribute("crf6b_multiline").setValue("Microsoft Dynamics CRM is a customer relationship management software package developed by Microsoft.");
 
}
 
Note:"crf6b_multiline" filed schema name


9.MultiSelect option Set 

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

    formContext.getAttribute("cr578_mulipleoptn").setValue([146630000, 146630001, 146630002]);

}

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

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

var dateofbirth = new Date();
 
var setdatevalue = formContext.getAttribute("crf6b_dateofbirth").setValue(dateofbirth);
 
}
 
 
Note:"crf6b_dateofbirth" filed schema name  
 
 
11.Lookup 
 
For lookup We need
  1. Id,
  2. Name,
  3. EntityType.
 
function setlookup(executionContext)

{

    var formContext = executionContext.getFormContext();

    var lookupValue = new Array();

     lookupValue[0]= new Object();

    lookupValue[0].id = "475b158c-541c-e511-80d3-3863bb347ba8"; //guid number

    lookupValue[0].name = "A.Datum";

    lookupValue[0].entityType = "account";

    formContext.getAttribute("crf6b_accountlookup").setValue(lookupValue);

}
 
Note:"crf6b_accountlookup" filed schema name  


12.Customer Lookup (Account or Contact)

function setcustomerlookup(executionContext)

{
    var formContext = executionContext.getFormContext();

    var lookupValue = new Array();

    lookupValue[0] = new Object();

    lookupValue[0].id = "d1d6a82b-cfa8-eb11-9442-000d3ac9ff82"; //guid number

    lookupValue[0].name = "Umer";

    lookupValue[0].entityType = "contact";

    formContext.getAttribute("crf6b_customerlookup").setValue(lookupValue);

}

Note:"crf6b_customerlookup" 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 - Get Value Method