快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

和记娱乐和记怡情下载:Dynamic CRM 2013学习记录(17)Javascript读写各种类型字段方法及技巧



我们常常要对表单里各类类型的字段进行读取或赋值,下面列出各类类型的读写措施及留意事变:

1. lookup 类型

清空值

var state = Xrm.Page.getAttribute("new_state");

if (state != null)

{

Xrm.Page.getAttribute("new_state").setValue(null);

}

读取值

var state = new Array();

state = Xrm.Page.getAttribute("new_state").getValue();

if(state != null)

{

var stateText = state[0].name;

var stateId = state[0].id;

var stateType = state[0].entityType;

alert("和记娱乐和记怡情下载State is: " + stateText + ", ID: " + stateId + "

of type: " + stateType);

}

分外要留意这里掏出来的值,必然要加[0],不然取不到值

赋值

var state = new Array();

state[0] = new Object();

state[0].id = "{BA0762E4-64D2-E111-909E-00155D6C871A}";

state[0].name = "New York";

state[0].entityType = "new_state";

Xrm.Page.getAttribute("new_sta和记娱乐和记怡情下载te").setValue(state);

2. Option sets

读取值

var sval = Xrm.Page.getAttribute("new_optionset").getSelectedOption().text;

var sval = Xrm.Page.getAttribute("new_optionset").getSelectedOption().value;

分手读取显示文本和值

别的,我们还可以用下面的措施来获取text和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 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("Contact birthday is: " + myContactBirthday);

var year = myContactBirthday.getFullYear();

var month = myContactBirthday.getMonth(); // from 0 to 11

var day = myContactBirthday.getDate(); // from 1 to 31

month = month + 1;

alert("Year: " + year + ", Month: " + month + ",和记娱乐和记怡情下载 Day: " + day);

赋值

var currentDateTime = new Date();

Xrm.Page.getAttribute("new_myDate").setValue(currentDateTime);

4. Currency

读取值

var myCurrencyField;

myCurrencyField = Xrm.Page.getAttribute("new_currencyfield").getValue();

alert("The value of this Currency field is: " + 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("The number in the field is: 和记娱乐和记怡情下载" + myNumber);

赋值

Xrm.Page.getAttribute("new_text").setValue("abc");

Xrm.Page.getAttribute("new_number").setValue(123);

您可能还会对下面的文章感兴趣: