ButtonClick: function (EntityName) {
var testEntity = {};
//主属性,名称字段,只能是单行文本
testEntity.new_name = "通过代码新增的记录";
//为单行文本字段赋值
testEntity.new_SingleLine = "This account was created by the JavaScriptRESTDataOperations sample.";
//为两个选项字段赋值,只能赋值为true或者false
testEntity.new_TwoOptionSet = true;
//为选项集字段赋值,为整数,是选项集的存储值,不是显示值
testEntity.new_OptionSet = { Value: 100000001 };
//为货币字段赋值
testEntity.new_Currency = { Value: "20000.1" };
//为
浮点数字段赋值,小数即可
testEntity.new_Float = 10.2;
//为
十进制字段赋值,特别注意要用引号引用起来
testEntity.new_Decimal = "104.1";
//为整数字段赋值
testEntity.new_Integer = 200;
//为日期和时间字段赋值
testEntity.new_Datetime = new Date();
//为多行文本字段赋值
testEntity.new_MultiLine = "多行文本字段的值多行文本字段的值多行文本字段的值多行文本字段的值----多行文本字段的值";
//为查找字段赋值
testEntity.new_Lookup = { Id: "F3A0BB75-F3AD-E311-80B4-00155D016705", LogicalName: "account", Name: "随便什么值" };
SDK.REST.createRecord(
testEntity,
"new_Test2013",
function (TestEntity) {
Xrm.Utility.alertDialog("新增记录成功,记录id是" + TestEntity.new_Test2013Id + "按确定按钮后将打开新增的记录",
function () {
Xrm.Utility.openEntityForm(EntityName, TestEntity.new_Test2013Id);
});
},
function errorHandler(error) {
alert('Error message:' + error.message);
}
);
}