We often have to read or assign the various types of fields in the form, and the following lists the various types of reading and writing methods and considerations:
1. Lookup type
var state = Xrm.Page.getAttribute ("new_state");
if null)
{
Xrm.Page.getAttribute ("new_state"). SetValue (null);
}
var New Array ();
State = Xrm.Page.getAttribute ("new_state"). GetValue ();
if null)
{
var statetext = state[0]. name;
var stateid = state[0].id;
var stateType = State[0].entitytype;
Alert ("" + statetext + "" + Stateid + "
of type: " + stateType);
}
Pay special attention to the value taken here, must add [0], or not get the value
var New Array ();
New Object ();
State[0].id = "{ba0762e4-64d2-e111-909e-00155d6c871a}";
State[0]. name = "New York";
State[0].entitytype = "new_state";
Xrm.Page.getAttribute ("new_state"). SetValue (state);
2. Option Sets
var sval = Xrm.Page.getAttribute ("new_optionset"). Getselectedoption (). text;
var sval = Xrm.Page.getAttribute ("new_optionset"). Getselectedoption (). value;
Read display text and values, respectively
In addition, we can use the following method to get the text and value:
var sval = Xrm.Page.getAttribute ("new_optionset"). GetText ();
var sval = Xrm.Page.getAttribute ("new_optionset"). GetValue ();
function Setosvalue (Osname, Oslabel)
{
var options = Xrm.Page.getAttribute (osname). GetOptions ();
for (i = 0; i < options.) length; i++)
{
if (Options[i].text = = Oslabel)
Xrm.Page.getAttribute (Osname). SetValue (Options[i].value);
}
}
3. Datetime
var mycontactbirthday;
Mycontactbirthday = Xrm.Page.getAttribute ("birthdate"). GetValue ();
Alert ("" + mycontactbirthday);
var year = Mycontactbirthday.getfullyear ();
var //From 0 to one
var //from 1 to
Month = month + 1;
Alert ("+ year +""+ month +""+ Day");
var New Date ();
Xrm.Page.getAttribute ("new_mydate"). SetValue (Currentdatetime);
4. Currency
var mycurrencyfield;
Mycurrencyfield = Xrm.Page.getAttribute ("new_currencyfield"). GetValue ();
Alert ("" + Mycurrencyfield);
var mycurrencyvalue = 6.25;
Xrm.Page.getAttribute ("new_currencyfield"). SetValue (parsefloat(mycurrencyvalue));
5. Number, text
var mynumber;
MyNumber = Xrm.Page.getAttribute ("new_number"). GetValue ();
Alert ("" + mynumber);
Xrm.Page.getAttribute ("new_text"). SetValue ("ABC");
Xrm.Page.getAttribute ("new_number"). SetValue (123);
Dynamic CRM 2013 Learning Notes Series Rollup
Dynamic CRM 2013 Learning Notes (17) JS Read and write various types of field methods and techniques