我们写程序常用的就是获取字段的值,对于不同的字段类型,通过getValue() 获取到的值如下,这个表摘自SDK中的 Xrm.Page.data.entity attribute (client-side reference) 章节。
Attribute Type | Return Type | ||
boolean | |||
datetime | To get the string version of a date using the Microsoft Dynamics CRM user’s locale preferences, use the format and localeFormat methods. Other methods will format dates using the operating system locale rather than the user’s Microsoft Dynamics CRM locale preferences. | ||
decimal | |||
double | |||
integer | |||
lookup | An array of lookup objects.
Each lookup has the following properties: entityType String: the name of the entity displayed in the lookup id String: The string representation of the GUID value for the record displayed in the lookup. name String: The text representing the record to be displayed in in the lookup. | ||
memo | |||
money | |||
optionset | |||
string |
我具体通过下面的代码来演示各种字段获取值得方法:
elseif(Xrm.Page.ui.getFormType()==2){//打开现有记录来修改
Xrm.Page.data.entity.attributes.forEach(
function(attribute, index){
var attrType = attribute.getAttributeType();
switch(attrType)
{
case"boolean":
alert("字段类型:两个选项;\n字段逻辑名称:"+ attribute.getName()+":\n字段必输属性:"+ attribute.getRequiredLevel()+";\n提交属性:"+ attribute.getSubmitMode()+";\n值是否修改过:"+ attribute.getIsDirty()+"\n值:"+ attribute.getValue());
break;
case"datetime":
alert("字段类型:日期和时间;\n字段逻辑名称:"+ attribute.getName()+":\n字段必输属性:"+ attribute.getRequiredLevel()+";\n提交属性:"+ attribute.getSubmitMode()+";\n值是否修改过:"+ attribute.getIsDirty()+"\n值:"+ attribute.getValue());
break;
case"decimal":
alert("字段类型:十进制数;\n字段逻辑名称:"+ attribute.getName()+":\n字段必输属性:"+ attribute.getRequiredLevel()+";\n提交属性:"+ attribute.getSubmitMode()+";\n值是否修改过:"+ attribute.getIsDirty()+"\n值:"+ attribute.getValue());
break;
case"double":
alert("字段类型:浮点数;\n字段逻辑名称:"+ attribute.getName()+":\n字段必输属性:"+ attribute.getRequiredLevel()+";\n提交属性:"+ attribute.getSubmitMode()+";\n值是否修改过:"+ attribute.getIsDirty()+"\n值:"+ attribute.getValue());
break;
case"integer":
alert("字段类型:整数;\n字段逻辑名称:"+ attribute.getName()+":\n字段必输属性:"+ attribute.getRequiredLevel()+";\n提交属性:"+ attribute.getSubmitMode()+";\n值是否修改过:"+ attribute.getIsDirty()+"\n值:"+ attribute.getValue());
break;
case"lookup":
alert("字段类型:查找;\n字段逻辑名称:"+ attribute.getName()+":\n字段必输属性:"+ attribute.getRequiredLevel()+";\n提交属性:"+ attribute.getSubmitMode()+";\n值是否修改过:"+ attribute.getIsDirty()+"\n显示值:"+ attribute.getValue()[0].name +";选择记录ID"+ attribute.getValue()[0].id +"选择记录逻辑名称:"+ attribute.getValue()[0].entityType);
break;
case"memo":
alert("字段类型:多行文本;\n字段逻辑名称:"+ attribute.getName()+":\n字段必输属性:"+ attribute.getRequiredLevel()+";\n提交属性:"+ attribute.getSubmitMode()+";\n值是否修改过:"+ attribute.getIsDirty()+"\n值:"+ attribute.getValue());
break;
case"money":
alert("字段类型:货币;\n字段逻辑名称:"+ attribute.getName()+":\n字段必输属性:"+ attribute.getRequiredLevel()+";\n提交属性:"+ attribute.getSubmitMode()+";\n值是否修改过:"+ attribute.getIsDirty()+"\n值:"+ attribute.getValue());
break;
case"optionset":
alert("字段类型:选项集;\n字段逻辑名称:"+ attribute.getName()+":\n字段必输属性:"+ attribute.getRequiredLevel()+";\n提交属性:"+ attribute.getSubmitMode()+";\n值是否修改过:"+ attribute.getIsDirty()+"\n选择值:"+ attribute.getValue()+"选择文本:"+ attribute.getText());
break;
case"string":
alert("字段类型:单行文本;\n字段逻辑名称:"+ attribute.getName()+":\n字段必输属性:"+ attribute.getRequiredLevel()+";\n提交属性:"+ attribute.getSubmitMode()+";\n值是否修改过:"+ attribute.getIsDirty()+"\n值:"+ attribute.getValue());
break;
default:
alert("未知");
}
});
}
效果如下,需要注意查找字段获取值得分析。
转载于:https://blog.51cto.com/wenzengliu/1788532