Get and Set values of Data Types in Microsoft Dynamics CRM
Using Java Script
There are 13 datatype available in Dynamics 365.
|
|
|
|
|
|
|
|
|
|
|
|
|
The following statements guide you on how to get and set the respective values.
1.Datatype: Single Line of Text (or) Multiple Line Of Text
-
- Get Value:
var str = Xrm.Page.getAttribute(“attribute logical name”).getValue();
-
-
-
- Ex : Var str = Xrm.Page.getAttribute(“new_singleline”).getValue();
-
- Set Value:
-
Xrm.Page.getAttribute(“attribute logical name”).setValue(“Test”);
-
-
-
- Ex : Xrm.Page.getAttribute(“new_txtsingleline”).setValue(“Test”);
-
-
2. Datatype: Option Set
-
- Get Value:
var Opvalue = Xrm.Page.getAttribute(“attribute logical name”).getValue();
-
-
-
- This will return selected option value.
- Ex : Var Opvalue = Xrm.Page.getAttribute(“new_optionset”).getValue();
- var Optext = Xrm.Page.getAttribute(“attribute logical name”).getText();
- This will return selected text value .Like Vendor,Customer,Retailer
- Ex : Var Optext = Xrm.Page.getAttribute(“new_optionset”).getText();
-
- Set Value: (Option Set)
- Xrm.Page.getAttribute(“attribute logical name”).setValue(1);
- Ex : Xrm.Page.getAttribute(“new_txtoptionset”).setValue(1);
- Xrm.Page.getAttribute(“attribute logical name”).setValue(1);
-
Datatype: Two Options
-
- Get Value:
var TwoOpvalue = Xrm.Page.getAttribute(“attribute logical name”).getValue();
-
-
-
- This will return true or false
-
-
-
-
-
- Ex : Xrm.Page.getAttribute(“new_twooptions”).getValue();
-
-
var TwoOptext = Xrm.Page.getAttribute(“attribute logical name”).getText();
-
-
-
- This will return selected text value .Like yes or No.
- Ex : Var TwoOptext=Xrm.Page.getAttribute(“new_twooptions”).getText();
-
- Set Value: (Two Options)
-
Xrm.Page.getAttribute(“attribute logical name”).setValue(TwoOpvalue);
-
-
-
- Ex : Xrm.Page.getAttribute(“new_txttwooptions”).setValue(TwoOpvalue);
-
-
- 4. Datatype: Lookup
-
- Get Value:
var lookupValue = Xrm.Page.getAttribute(“attribute logical name”).getValue();
var ID= lookupValue [0].id;
-
-
-
- Will return id of the selected record.
-
-
var Name= lookupValue[0].name;
-
-
-
- Will return selected text value.
-
-
var LogicalName= lookupValue[0].entityType;
-
-
-
- Will return selected record logical name.
-
-
Ex : var lookupValue = Xrm.Page.getAttribute(“new_txtlookup”).getValue();
-
- Set Value: (Lookup Field)
Xrm.Page.getAttribute(“attribute logical name “).setValue([{ id: “record Guid”, name:“recordname(Optional)”, entityType: “entity logical name” }]);
Ex : Xrm.Page.getAttribute(“new_txtlookup”).setValue([{ id: ID, name: Name, entityType: LogicalName}]);
Or
Var lookupval=new Array();
lookupVal[0] = new Object();
lookupVal[0].id = Id;
lookupVal[0].name = Name;
lookupVal[0].entityType =LogicalName;
Xrm.Page.getAttribute(“new_parentcustomerid2”).setValue(lookupVal);
5. Datatype: Decimal
-
- Get Value:
- var decvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Ex : Var decvalue= Xrm.Page.getAttribute(“new_decimal”).getValue();
- var decvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Set Value:
- Xrm.Page.getAttribute(“attribute logical name”).setValue(decvalue);
- Ex : Xrm.Page.getAttribute(“new_txtdecimal”).setValue(decvalue);
- Xrm.Page.getAttribute(“attribute logical name”).setValue(decvalue);
- Get Value:
6. Datatype: Date and Time
-
- Get Value:
- var datetime= Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Ex: var datetime= Xrm.Page.getAttribute(“new_datetime”).getValue();
- var datetime= Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Set Value:
- Xrm.Page.getAttribute(“attribute logical name”).setValue(datetime);
- Ex : Xrm.Page.getAttribute(“new_txtdatetime”).setValue(datetime);
- Xrm.Page.getAttribute(“attribute logical name”).setValue(datetime);
- Get Value:
7. Datatype: Whole Number
-
- Get Value:
- var Wholevalue = Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Ex : Var Wholevalue = Xrm.Page.getAttribute(“new_wholenumber”).getValue();
- var Wholevalue = Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Set Value:
- Xrm.Page.getAttribute(“attribute logical name”).setValue(Wholevalue);
- Ex : Xrm.Page.getAttribute(“new_txtwholenumber”).setValue(Wholevalue);
- Xrm.Page.getAttribute(“attribute logical name”).setValue(Wholevalue);
- Get Value:
8. Datatype: Floating Point Number
-
- Get Value:
- var Floatvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Ex : Var Floatvalue= Xrm.Page.getAttribute(“new_floatnumber”).getValue();
- var Floatvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Set Value:
- Xrm.Page.getAttribute(“attribute logical name”).setValue(Floatvalue);
- Ex : Xrm.Page.getAttribute(“new_txtfloatnumber”).setValue(Floatvalue);
- Xrm.Page.getAttribute(“attribute logical name”).setValue(Floatvalue);
- Get Value:
9. Datatype: Currency
-
- Get Value:
- var Currencyvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Ex : var Currencyvalue= Xrm.Page.getAttribute(“new_currency”).getValue();
- var Currencyvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Set Value:
- Xrm.Page.getAttribute(“attribute logical name”).setValue(Currencyvalue);
- Ex: Xrm.Page.getAttribute(“new_txtcurrencyvalue”).setValue(Currencyvalue);
- Xrm.Page.getAttribute(“attribute logical name”).setValue(Currencyvalue);
- Get Value:
10. Datatype: Multi Select OptionSet
-
- Get Value:
- var Mulopvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Ex : var Mulopvalue= Xrm.Page.getAttribute(“new_multiselectoptionset”).getValue();
- var Mulopvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
- Set Value:
- Xrm.Page.getAttribute(“attribute logical name”).setValue(Mulopvalue);
- Ex : Xrm.Page.getAttribute(“new_txtmulopvalue”).setValue(Mulopvalue);
- Xrm.Page.getAttribute(“attribute logical name”).setValue(Mulopvalue);
- Get Value:
11. Datatype : Customer
Customer datatype is similar to lookup but it contains only account and contact entity type only.
-
- Get Value:
var lookupValue = Xrm.Page.getAttribute(“attribute logical name”).getValue();
var ID= lookupValue [0].id;
-
-
-
- Will return id of the selected record.
-
-
var Name= lookupValue[0].name;
-
-
-
- Will return selected text value.
-
-
var LogicalName= lookupValue[0].entityType;
-
-
-
- Will return selected record logical name.
-
-
Ex : var lookupValue = Xrm.Page.getAttribute(“new_txtlookup”).getValue();
-
- Set Value: (Lookup Field)
Xrm.Page.getAttribute(“attribute logical name “).setValue([{ id: “record Guid”, name:“recordname(Optional)”, entityType: “entity logical name” }]);
Ex : Xrm.Page.getAttribute(“new_txtlookup”).setValue([{ id: ID, name: Name, entityType: LogicalName}]);
Or
Var lookupval=new Array();
lookupVal[0] = new Object();
lookupVal[0].id = Id;
lookupVal[0].name = Name;
lookupVal[0].entityType =LogicalName; // account or contact
Xrm.Page.getAttribute(“new_parentcustomerid2”).setValue(lookupVal);