createRecord (Tham khảo API JavaScript) cho Khung tích hợp kênh Dynamics 365 2.0

Tạo bản ghi thực thể.

Cú pháp

Microsoft.CIFramework.createRecord(entityLogicalName, data).then(successCallback, errorCallback);

Tham số

Tên Type Bắt buộc Description
tên thực thể Xâu Có Tên logic của thực thể bạn muốn tạo. Ví dụ: "tài khoản".
dữ liệu Xâu Có Chuỗi xác định các thuộc tính và giá trị cho bản ghi thực thể mới.
successCallback Chức năng Không Một hàm để gọi khi một bản ghi được tạo.
errorCallback Chức năng Không Một hàm để gọi khi hoạt động không thành công.

Giá trị trả về

Khi thành công, trả về một promise chứa một chuỗi với các thuộc tính và giá trị của chúng.

Ví dụ

Mã mẫu minh họa cách tạo bản ghi người liên hệ mẫu.

var entityLogicalName = "contact";
var data = {
    "firstname": "Sample",
    "lastname": "Contact",
    "fullname": "Sample Contact",
    "emailaddress1": "contact@contoso.com",
    "jobtitle": "Sr. Marketing Manager",
    "telephone1": "555-0109",
    "description": "Default values for this record were set programmatically."
}
// create contact record
var jsonData = JSON.stringify(data);
Microsoft.CIFramework.createRecord(entityLogicalName,jsonData).then(
    function success (result) {
      res=JSON.parse(result);
          console.log("Contact created with ID: " + res.id);
          //perform operations on record creation
      },
      function (error) {
          console.log(error);
          //handle error conditions
      }
  ); 

Ví dụ sau đây cho thấy cách bạn có thể chuyển giá trị tra cứu thay vì văn bản thuần túy trong biến data.

var data =
    {
        "name": "Sample Account",
        "primarycontactid@odata.bind": "/contacts(3518ddae-2f46-e911-8190-000d3a6ce16d)"
    }
var jsonData = JSON.stringify(data);
Microsoft.CIFramework.createRecord("account",jsonData).then(
    function success (result) {
      res=JSON.parse(result);
          console.log("Contact created with ID: " + res.id);
          //perform operations on record creation
      },
      function (error) {
          console.log(error);
          //handle error conditions
      }
);