Xrm.WebApi.online.execute (การอ้างอิง API ไคลเอ็นต์)

ดําเนินการกระทํา ฟังก์ชัน หรือการดําเนินการ CRUD เดียว

Note

วิธีนี้ได้รับการสนับสนุนสําหรับโหมดออนไลน์ (Xrm.WebApi.online) เท่านั้น

ไวยากรณ์

Xrm.WebApi.online.execute(request).then(successCallback, errorCallback);

พารามิเตอร์

ชื่อ ประเภท ต้องมี คำอธิบาย
request วัตถุ ใช่ ออบเจ็กต์ที่คุณส่งผ่านไปยังจุดสิ้นสุด API เว็บเพื่อดําเนินการตามคําขอการดําเนินการ ฟังก์ชัน หรือ CRUD วัตถุจะแสดง getMetadata เมธอด ผ่านต้นแบบ ที่คุณใช้เพื่อกําหนดเมตาดาต้าสําหรับการดําเนินการ ฟังก์ชัน หรือคําขอ CRUD ที่คุณต้องการดําเนินการ ดู เมธอด request.getMetadata
successCallback ฟังก์ชัน ไม่ใช่ ฟังก์ชันที่จะเรียกใช้เมื่อการดําเนินการสําเร็จ ดู ค่าที่ส่งกลับ
errorCallback ฟังก์ชัน ไม่ใช่ ฟังก์ชันที่จะเรียกใช้เมื่อการดําเนินการล้มเหลว วัตถุที่มีคุณสมบัติต่อไปนี้จะถูกส่งผ่าน:
- errorCode:เลข รหัสข้อผิดพลาดเป็นเลขทศนิยมบวก ตัวอย่างเช่น รหัสข้อผิดพลาดที่จัดทําเป็น 0x80040333 จะถูกส่งกลับเป็น2147746611
- message:เชือก ข้อความแสดงข้อผิดพลาดที่อธิบายปัญหา

request.getMetadata method

เม getMetadata ธอด มีพารามิเตอร์ต่อไปนี้:

ชื่อ ประเภท ต้องมี คำอธิบาย
boundParameter สตริง ไม่ใช่ ชื่อของพารามิเตอร์ที่ผูกไว้สําหรับการดําเนินการหรือฟังก์ชันที่จะดําเนินการ
- ระบุว่า undefined คุณกําลังดําเนินการตามคําขอ CRUD หรือไม่
- ระบุว่า null การดําเนินการหรือฟังก์ชันที่จะดําเนินการไม่ได้ผูกไว้กับตารางใดหรือไม่
- ระบุว่า entity การดําเนินการหรือฟังก์ชันที่จะดําเนินการถูกผูกไว้กับตารางหรือไม่
operationName สตริง ไม่ใช่ ชื่อของการดําเนินการ ฟังก์ชัน หรือค่าใดค่าหนึ่งต่อไปนี้ถ้าคุณกําลังดําเนินการคําขอ CRUD: Create, RetrieveUpdate, หรือDelete
operationType ตัวเลข ไม่ใช่ ระบุชนิดของการดําเนินการที่คุณกําลังดําเนินการ ระบุค่าใดค่าหนึ่งต่อไปนี้:
- 0:การเคลื่อนไหว
- 1:ฟังก์ชัน
- 2: CRUD
parameterTypes วัตถุ ใช่ เมตาดาต้าสําหรับชนิดพารามิเตอร์ วัตถุมีค่าต่อไปนี้:
enumProperties : วัตถุ (เป็นทางเลือก) เมตาดาต้าสําหรับชนิด enum วัตถุ มีค่าสตริงสองค่า: name และvalue
structuralProperty :เลข ประเภทของชนิดพารามิเตอร์ ระบุค่าใดค่าหนึ่งต่อไปนี้:
- 0:ไม่คุ้นเคย
- 1: PrimitiveType
- 2: ComplexType
- 3: EnumerationType
- 4:เหล่า
- 5: EntityType
typeName :เชือก ชื่อที่ตรงตามหลักเกณฑ์ของชนิดพารามิเตอร์

ค่าที่ส่งกลับ

ในความสําเร็จ ส่งกลับวัตถุสัญญาไปยัง successCallback ด้วยคุณสมบัติต่อไปนี้:

ชื่อ ประเภท คำอธิบาย
body(ไม่สนับสนุน) วัตถุ ร่างกายตอบสนอง
headers วัตถุ ส่วนหัวของคําตอบ
ok แบบบูลีน ระบุว่าคําขอสําเร็จหรือไม่
status ตัวเลข ค่าตัวเลขในรหัสสถานะการตอบสนอง ตัวอย่าง: 200
statusText สตริง คําอธิบายเกี่ยวกับรหัสสถานะการตอบสนอง ตัวอย่าง: OK
type(ไม่สนับสนุน) สตริง ชนิดการตอบสนอง ค่าคือ: สตริงว่าง (ค่าเริ่มต้น), arraybuffer, blobdocument, json, และtext
url สตริง ร้องขอ URL ของการดําเนินการ ฟังก์ชัน หรือคําขอ CRUD ที่คุณส่งไปยังจุดสิ้นสุดของ API เว็บ
json สัญญา พารามิเตอร์สําหรับผู้รับมอบสิทธิ์การเรียกกลับเป็นชนิด ใด ๆ (วัตถุ JSON)
text สัญญา พารามิเตอร์ไปยังผู้รับมอบสิทธิ์การเรียกกลับเป็นสตริง

ตัวอย่าง

ค้นหาตัวอย่างเหล่านี้ในส่วนต่อไปนี้:

ตัวอย่าง แสดงตัวอย่าง
ดําเนินการ วิธีการดําเนินการ WinOpportunity เพื่อทําเครื่องหมายโอกาสเป็นชนะ
ดําเนินการฟังก์ชัน วิธีการดําเนินการWhoAmICalculateRollupFieldฟังก์ชัน , , RetrieveDuplicatesและ และ InitializeFrom และอ่านคําตอบ
สร้างเรกคอร์ด วิธีการสร้างเรกคอร์ดบัญชีโดยใช้ออบเจ็กต์คําขอ
เรียกใช้ระเบียน วิธีการเรียกใช้ชื่อของเรกคอร์ดบัญชีโดยระบุ ID และคอลัมน์ที่จะส่งกลับ
อัปเดตระเบียน วิธีการอัปเดตชื่อของเรกคอร์ดบัญชีโดยใช้ออบเจ็กต์คําขอ
ลบเรกคอร์ด วิธีการลบเรกคอร์ดบัญชีโดยการระบุตารางและรหัสบัญชีนั้น
เชื่อมโยงระเบียน วิธีการเชื่อมโยงบัญชีกับผู้ติดต่อหลายรายผ่านคุณสมบัติการนําทางที่มีค่าคอลเลกชัน
แยกระเบียน วิธีการลบการเชื่อมโยงระหว่างบัญชีกับผู้ติดต่อหนึ่งรายผ่านคุณสมบัติการนําทางที่มีค่าคอลเลกชัน

เคล็ดลับ

ใช้ Dataverse REST Builder เพื่อสร้างรหัส JavaScript ที่ใช้ Xrm.WebApi.online.execute เมธอด

ตัวอย่างการดําเนินการ

ตัวอย่างต่อไปนี้สาธิตวิธีการดําเนินการ WinOpportunity ที่พบในโซลูชัน Dynamics 365 for Sales วัตถุคําขอถูกสร้างขึ้นตามข้อกําหนดการดําเนินการใน การดําเนินการที่ไม่ถูกผูกไว้

var Sdk = window.Sdk || {};
/**
 * Request to win an opportunity
 * @param {Object} opportunityClose - The opportunity close activity associated with this state change.
 * @param {number} status - Status of the opportunity.
 */
Sdk.WinOpportunityRequest = function(opportunityClose, status) {
    this.OpportunityClose = opportunityClose;
    this.Status = status;
};

// NOTE: The getMetadata property should be attached to the function prototype instead of the
// function object itself.
Sdk.WinOpportunityRequest.prototype.getMetadata = function () {
    return {
        boundParameter: null,
        parameterTypes: {
            "OpportunityClose": {
                "typeName": "mscrm.opportunityclose",
                "structuralProperty": 5 // Entity Type
            },
            "Status": {
                "typeName": "Edm.Int32",
                "structuralProperty": 1 // Primitive Type
            }
        },
        operationType: 0, // This is an action. Use '1' for functions and '2' for CRUD
        operationName: "WinOpportunity",
    };
};

var opportunityClose = {
    "opportunityid@odata.bind": "/opportunities(c60e0283-5bf2-e311-945f-6c3be5a8dd64)",
    "description": "Product and maintenance for 2018",
    "subject": "Contract for 2018"
}

// Construct a request object from the metadata
var winOpportunityRequest = new Sdk.WinOpportunityRequest(opportunityClose, 3);

// Use the request object to execute the function
Xrm.WebApi.online.execute(winOpportunityRequest).then(function (response) {
    if (response.ok) {
        console.log("Status: %s %s", response.status, response.statusText);
        // The WinOpportunityRequest does not return any response body content. So we
        // need not access the response.json() property.

        // Perform other operations as required.
    }
})
.catch(function(error) {
    console.log(error.message);
    // handle error conditions
});

ใช้ตัวอย่างฟังก์ชัน

ตัวอย่างต่อไปนี้สาธิตวิธีการดําเนินการ ฟังก์ชัน WhoAmI:

var Sdk = window.Sdk || {};
/**
 * Request to execute WhoAmI function
 */
Sdk.WhoAmIRequest = function () { };

// NOTE: The getMetadata property should be attached to the function prototype instead of the
//       function object itself.
Sdk.WhoAmIRequest.prototype.getMetadata = function () {
    return {
        boundParameter: null,
        parameterTypes: {},
        operationType: 1, // This is a function. Use '0' for actions and '2' for CRUD
        operationName: "WhoAmI",
    };
};

// Construct a request object from the metadata
var whoAmIRequest = new Sdk.WhoAmIRequest();

// Use the request object to execute the function
Xrm.WebApi.online.execute(whoAmIRequest)
.then(function (response) {
    if (response.ok) {
        console.log("Status: %s %s", response.status, response.statusText);

        // Use response.json() to access the content of the response body.
        return response.json();
    }
}
)
.then(function (responseBody) {
    console.log("User Id: %s", responseBody.UserId);
    // perform other operations as required;
})
.catch(function (error) {
    console.log(error.message);
    // handle error conditions
});

ตัวอย่างต่อไปนี้สาธิตวิธีการดําเนินการฟังก์ชัน CalculateRollupField :

var Sdk = window.Sdk || {};

Sdk.CalculateRollupFieldRequest = function(target, fieldName) {
    this.Target = target;
    this.FieldName = fieldName;
};

// NOTE: The getMetadata property should be attached to the function prototype instead of the
//       function object itself.
Sdk.CalculateRollupFieldRequest.prototype.getMetadata = function() {
    return {
        boundParameter: null,
        parameterTypes: {
            "Target": {
                "typeName": "mscrm.crmbaseentity",
                "structuralProperty": 5
            },
            "FieldName": {
                "typeName": "Edm.String",
                "structuralProperty": 1
            }
        },
        operationType: 1, // This is a function. Use '0' for actions and '2' for CRUD
        operationName: "CalculateRollupField"
    };
};

// Create variables to point to a quote record and to a specific column
var quoteId = {
    "@odata.type": "Microsoft.Dynamics.CRM.quote",
    "quoteid": "7bb01e55-2394-ea11-a811-000d3ad97943"
};

// The roll-up column for which we want to force a re-calculation
var fieldName = "new_test_rollup";

// Create variable calculateRollupFieldRequest and pass those variables created above
var calculateRollupFieldRequest = new Sdk.CalculateRollupFieldRequest(quoteId, fieldName);

// Use the request object to execute the function
Xrm.WebApi.online.execute(calculateRollupFieldRequest)
.then(function(response) {
    if (response.ok) { // If a response was received.
        console.log("Status: %s %s", response.status, response.statusText);

        // Use response.json() to access the content of the response body.
        return response.json();
    }
})
.then(function(responseBody) { 
    //Do something with the response
    console.log("The response is: %s", responseBody);
})
.catch(function(error) {
    console.log(error.message);
    // handle error conditions
});

ตัวอย่างต่อไปนี้สาธิตวิธีการดําเนินการฟังก์ชัน RetrieveDuplicates :

var Sdk = window.Sdk || {};

Sdk.RetrieveDuplicatesRequest = function(businessEntity, matchingEntityName, pagingInfo) {
    this.BusinessEntity = businessEntity;
    this.MatchingEntityName = matchingEntityName;
    this.PagingInfo = pagingInfo;

};

// NOTE: The getMetadata property should be attached to the function prototype instead of the
// function object itself.
Sdk.RetrieveDuplicatesRequest.prototype.getMetadata = function() {
    return {
        boundParameter: null,
        parameterTypes: {
            "BusinessEntity": {
                "typeName": "mscrm.crmbaseentity",
                "structuralProperty": 5 // Entity Type
            },
            "MatchingEntityName": {
                "typeName": "Edm.String",
                "structuralProperty": 1 // Primitive Type
            },
            "PagingInfo": {
                "typeName:": "mscrm.PagingInfo", // Complex Type
                "structuralProperty": 5
            }
        },
        operationType: 1, // This is a function. Use '0' for actions and '2' for CRUD
        operationName: "RetrieveDuplicates",
    };
};

// Create a variable to point to a contact record and with specific data in the needed columns
var contactRecord = {
    "@odata.type": "Microsoft.Dynamics.CRM.contact",
    "firstname": "Test",
    "lastname": "Account"
};

// Create a paging object to keep track of the current page and how many records we get per page
var pagingInfo = {
    "PageNumber": 1,
    "Count": 10
};

// Create the variable retrieveDuplicatesRequest to build the request
var retrieveDuplicatesRequest = new Sdk.RetrieveDuplicatesRequest(contactRecord, "contact", pagingInfo);

// Use the request object to execute the function
Xrm.WebApi.online.execute(retrieveDuplicatesRequest)
.then(function (response) {
    if (response.ok) {
        console.log("Status: %s %s", response.status, response.statusText);

        // Use response.json() to access the content of the response body.
        return response.json();
    }
})
.then(function(responseBody) { 
    // Do something with the response
    console.log("The response is: %s", responseBody);
})
.catch(function(error) {
    console.log(error.message);
    // handle error conditions
});

ตัวอย่างต่อไปนี้สาธิตวิธีการดําเนินการฟังก์ชัน InitializeFrom :

var Sdk = window.Sdk || {};

Sdk.InitializeFromRequest = function (
  entityMoniker,
  targetEntityName,
  targetFieldType
) {
  this.EntityMoniker = entityMoniker;
  this.TargetEntityName = targetEntityName;
  this.TargetFieldType = targetFieldType;
};

// NOTE: The getMetadata property should be attached to the function prototype instead of the
// function object itself.
Sdk.InitializeFromRequest.prototype.getMetadata = function () {
  return {
    boundParameter: null,
    parameterTypes: {
      EntityMoniker: {
        typeName: "mscrm.crmbaseentity",
        structuralProperty: 5, //Entity Type
      },
      TargetEntityName: {
        typeName: "Edm.String",
        structuralProperty: 1, // PrimitiveType
      },
      TargetFieldType: {
        typeName: "Microsoft.Dynamics.CRM.TargetFieldType",
        structuralProperty: 3, // Enum Type
        enumProperties: [
          {
            name: "All",
            value: 0,
          },
          {
            name: "ValidForCreate",
            value: 1,
          },
          {
            name: "ValidForUpdate",
            value: 2,
          },
          {
            name: "ValidForRead",
            value: 3,
          },
        ],
      },
    },
    operationType: 1, // This is a function. Use '0' for actions and '2' for CRUD
    operationName: "InitializeFrom",
  };
};

// Create a variable to point to tje parent account record
var parentAccountRecord = {
  "@odata.type": "Microsoft.Dynamics.CRM.account",
  accountid: "141da047-eaad-eb11-b1b4-000d3ac581a0",
};

// Create a variable for the target entity name
var targetEntityName = "account";

// Create a variable for the target field type
var targetFieldType = 0;

// Build the request
var initializeFromRequest = new Sdk.InitializeFromRequest(
  parentAccountRecord,
  targetEntityName,
  targetFieldType
);

// Execute the request
Xrm.WebApi.online.execute(initializeFromRequest)
.then(function (response) {
    if (response.ok) {
        console.log("Status: %s %s", response.status, response.statusText);

        // Use response.json() to access the content of the response body.
        return response.json();
    }
})
.then(function(responseBody) { 
    // Do something with the response
    console.log("The response is: %s", responseBody);
})
.catch(function(error) {
    console.log(error.message);
    // handle error conditions
});

ดําเนินการ CRUD

ตัวอย่างการสร้างเรกคอร์ด

ตัวอย่างต่อไปนี้สาธิตวิธีการดําเนินการสร้าง

var Sdk = window.Sdk || {};

/**
 * Request to execute a create operation
 */
Sdk.CreateRequest = function(entityName, payload) {
    this.etn = entityName;
    this.payload = payload;
};

// NOTE: The getMetadata property should be attached to the function prototype instead of the
// function object itself.
Sdk.CreateRequest.prototype.getMetadata = function () {
    return {
        boundParameter: null,
        parameterTypes: {},
        operationType: 2, // This is a CRUD operation. Use '0' for actions and '1' for functions
        operationName: "Create",
    };
};
// Construct a request object from the metadata
var payload = {
    name: "Fabrikam Inc."
};
var createRequest = new Sdk.CreateRequest("account", payload);

// Use the request object to execute the function
Xrm.WebApi.online.execute(createRequest)
.then(function (response) {
    if (response.ok) {
        console.log("Status: %s %s", response.status, response.statusText);
        
        // The Create request does not return any response body content. So we
        // need not access the response.json() property.

        // Perform other operations as required.
    }
})
.catch(function(error) {
    console.log(error.message);
    // handle error conditions
});

เรียกใช้ตัวอย่างเรกคอร์ด

ตัวอย่างต่อไปนี้สาธิตวิธีการดําเนินการเรียกใช้

var Sdk = window.Sdk || {};

/**
 * Request to execute a retrieve operation
 */
Sdk.RetrieveRequest = function(entityReference, columns) {
    this.entityReference = entityReference;
    this.columns = columns;
};
// NOTE: The getMetadata property should be attached to the function prototype instead of the
// function object itself.
Sdk.RetrieveRequest.prototype.getMetadata = function () {
    return {
        boundParameter: null,
        parameterTypes: {},
        operationType: 2, // This is a CRUD operation. Use '0' for actions and '1' for functions
        operationName: "Retrieve",
    };
};

// Construct request object from the metadata
var entityReference = {
    entityType: "account",
    id: "d2b6c3f8-b0fa-e911-a812-000d3a59fa22"
};
var retrieveRequest = new Sdk.RetrieveRequest(entityReference, ["name"]);

// Use the request object to execute the function
Xrm.WebApi.online.execute(retrieveRequest)
.then(function (response) {
    if (response.ok) {
        console.log("Status: %s %s", response.status, response.statusText);

        // Use response.json() to access the content of the response body.
        return response.json();
    }
})
.then(function(responseBody) {
    console.log("Name: %s", responseBody.name);
    
    // perform other operations as required;
})
.catch(function(error) {
    console.log(error.message);
    // handle error conditions
});

ตัวอย่างการอัปเดตเรกคอร์ด

ตัวอย่างต่อไปนี้สาธิตวิธีการดําเนินการอัปเดต

var Sdk = window.Sdk || {};


/**
 * Request to execute an update operation
 */
Sdk.UpdateRequest = function(entityName, entityId, payload) {
    this.etn = entityName;
    this.id = entityId;
    this.payload = payload;
};

// NOTE: The getMetadata property should be attached to the function prototype instead of the
// function object itself.
Sdk.UpdateRequest.prototype.getMetadata = function () {
    return {
        boundParameter: null,
        parameterTypes: {},
        operationType: 2, // This is a CRUD operation. Use '0' for actions and '1' for functions
        operationName: "Update",
    };
};

// Construct a request object from the metadata
var payload = {
    name: "Updated Sample Account"
};
var updateRequest = new Sdk.UpdateRequest("account", "d2b6c3f8-b0fa-e911-a812-000d3a59fa22", payload);

// Use the request object to execute the function
Xrm.WebApi.online.execute(updateRequest)
.then(function (response) {
    if (response.ok) {
        console.log("Status: %s %s", response.status, response.statusText);

        // The Update request does not return any response body content. So we
        // need not access the response.json() property.
        
        // perform other operations as required;
    }
})
.catch(function(error) {
    console.log(error.message);
    // handle error conditions
});

ตัวอย่างการลบเรกคอร์ด

ตัวอย่างต่อไปนี้สาธิตวิธีการดําเนินการลบ

var Sdk = window.Sdk || {};

/**
 * Request to execute a delete operation
 */
Sdk.DeleteRequest = function(entityReference) {
    this.entityReference = entityReference;
};

// NOTE: The getMetadata property should be attached to the function prototype instead of the
// function object itself.
Sdk.DeleteRequest.prototype.getMetadata = function () {
        return {
            boundParameter: null,
            parameterTypes: {},
            operationType: 2, // This is a CRUD operation. Use '0' for actions and '1' for functions
            operationName: "Delete",
        };
    };
};
};

// Construct request object from the metadata
var entityReference = {
    entityType: "account",
    id: "d2b6c3f8-b0fa-e911-a812-000d3a59fa22"
};
var deleteRequest = new Sdk.DeleteRequest(entityReference);

// Use the request object to execute the function
Xrm.WebApi.online.execute(deleteRequest)
.then(function(response) {
    if (response.ok) {
        console.log("Status: %s %s", response.status, response.statusText);
        
        // The Delete request does not return any response body content. So we
        // need not access the response.json() property.

        // perform other operations as required;
    }
})
.catch(function(error) {
    console.log(error.message);
    // handle error conditions
});

ตัวอย่างการเชื่อมโยงเรกคอร์ด

ตัวอย่างโค้ดต่อไปนี้สาธิตวิธีการดําเนินการเชื่อมโยงคุณสมบัติการนําทางที่มีค่าคอลเลกชัน (ความสัมพันธ์แบบหนึ่งต่อกลุ่มและกลุ่มต่อกลุ่ม) สําหรับคุณสมบัติการนําทางแบบค่าเดียว (ความสัมพันธ์แบบกลุ่มต่อหนึ่ง หรือที่เรียกว่าคอลัมน์การค้นหา) คุณสามารถดําเนินการอัปเดตตามที่แสดงไว้ก่อนหน้านี้หรือใช้ Xrm.WebApi.updateRecord

var Sdk = window.Sdk || {};

/*
 * Request to execute an Associate operation.
 */
Sdk.AssociateRequest = function(target, relatedEntities, relationship) {
    this.target = target;
    this.relatedEntities = relatedEntities;
    this.relationship = relationship;
};

// NOTE: The getMetadata property should be attached to the function prototype instead of the
// function object itself.
Sdk.AssociateRequest.prototype.getMetadata = function() {
    return {
        boundParameter: null,
        parameterTypes: {},
        operationType: 2, // Associate and Disassociate fall under the CRUD umbrella
        operationName: "Associate"
    }
};

// Construct the target EntityReference object
var target = {
    entityType: "account",
    id: "0b4abc7d-7619-eb11-8dff-000d3ac5c7f9"
};

// Construct the related EntityReferences that the Target will be associated with.
var relatedEntities = [
    {
        entityType: "contact",
        id: "180a9aad-7619-eb11-8dff-000d3ac5c7f9"
    },
    {
        entityType: "contact",
        id: "753c58b4-7619-eb11-8dff-000d3ac5c7f9"
    }
];

// The name of the existing relationship to associate on.
var relationship = "new_account_contact";

var manyToManyAssociateRequest = new Sdk.AssociateRequest(target, relatedEntities, relationship)

Xrm.WebApi.online.execute(manyToManyAssociateRequest)
.then(function(response) {
    if (response.ok) {
        console.log("Status: %s %s", response.status, response.statusText);

        // The Associate request does not return any response body content. So we
        // need not access the response.json() property.

        // perform other operations as required;
    }
})
.catch(function(error) {
    console.log(error.message);
    // handle error conditions
});

แยกตัวอย่างระเบียน

ตัวอย่างโค้ดต่อไปนี้สาธิตวิธีการดําเนินการยกเลิกการเชื่อมโยงในคุณสมบัติการนําทางที่มีค่าคอลเลกชัน (ความสัมพันธ์แบบหนึ่งต่อกลุ่มและกลุ่มต่อกลุ่ม) สําหรับคุณสมบัติการนําทางแบบค่าเดียว (ความสัมพันธ์แบบกลุ่มต่อหนึ่ง หรือที่เรียกว่าคอลัมน์การค้นหา) คุณสามารถดําเนินการอัปเดตตามที่แสดงไว้ก่อนหน้านี้หรือใช้ Xrm.WebApi.updateRecord

Note

ซึ่งแตกต่างจากการดําเนินการเชื่อมโยง ซึ่งคุณสามารถใช้เพื่อเชื่อมโยงเรกคอร์ดเอนทิตีเป้าหมายกับเรกคอร์ดเอนทิตีที่เกี่ยวข้องหลายรายการในการดําเนินการเดียว การดําเนินการแยกความสัมพันธ์สามารถยกเลิกการเชื่อมโยงเรกคอร์ดเอนทิตีหนึ่งรายการจากเรกคอร์ดเอนทิตีเป้าหมายในแต่ละการดําเนินการเท่านั้น

var Sdk = window.Sdk || {};

/*
 * Request to execute a Disassociate operation.
 */
Sdk.DisassociateRequest = function(target, relatedEntityId, relationship) {
    this.target = target;
    this.relatedEntityId = relatedEntityId;
    this.relationship = relationship;
};

// NOTE: The getMetadata property should be attached to the function prototype instead of the
// function object itself.
Sdk.DisassociateRequest.prototype.getMetadata = function() {
    return {
        boundParameter: null,
        parameterTypes: {},
        operationType: 2, // Associate and Disassociate fall under the CRUD umbrella
        operationName: "Disassociate"
    }
};

// Construct the target EntityReference object
var target = {
    entityType: "account",
    id: "0b4abc7d-7619-eb11-8dff-000d3ac5c7f9"
};

// The GUID of the related entity record to disassociate.
var relatedEntityId = "180a9aad-7619-eb11-8dff-000d3ac5c7f9";

// The name of the existing relationship to disassociate from.
var relationship = "new_account_contact";

var manyToManyDisassociateRequest = new Sdk.DisassociateRequest(target, relatedEntityId, relationship)

Xrm.WebApi.online.execute(manyToManyDisassociateRequest)
.then(function(response) {
    if (response.ok) {
        console.log("Status: %s %s", response.status, response.statusText);

        // The Disassociate request does not return any response body content. So we
        // need not access the response.json() property.

        // perform other operations as required;
    }
})
.catch(function(error) {
    console.log(error.message);
    // handle error conditions
});

Xrm.WebApi