time 
设为首页】【收藏本站
当前位置: 主页 > ERP > CRM > Dynamic CRM 2013学习记录(17)Javascript读写各种类型字段方法及技巧

Dynamic CRM 2013学习记录(17)Javascript读写各种类型字段方法及技巧

时间:2015-01-08 15:54 点击:1084次 字体:[ ]




我们经常要对表单里各种类型的字段进行读取或赋值,下面列出各种类型的读写方法及注意事项:

 

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_state").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 < 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("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);

 



本文地址 : http://www.fengfly.com/plus/view-215521-1.html
标签: Dynamic CRM 2013 字段 JavaScript 读写
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码: