วิธีการตารางผกผันสําหรับหน้าที่สร้าง

ใช้วิธีการตารางของ dataApi วัตถุเพื่อสร้าง เรียกใช้ อัปเดต และลบแถวตาราง Dataverse และคอลัมน์ตัวเลือกคิวรี

วิธีการ คำอธิบาย
createRow สร้างแถวใหม่ในตารางที่ระบุ
deleteRow ลบแถวจากตารางที่ระบุ
getChoices เรียกใช้ตัวเลือกสําหรับชื่อคอลัมน์ตัวเลือกที่ระบุ
queryTable คิวรีตารางด้วยตัวเลือกที่ระบุ
retrieveRow ดึงข้อมูลแถวจากตารางที่ระบุด้วยตัวเลือกที่ระบุ
updateRow อัปเดตแถวที่มีอยู่ในตารางที่ระบุ

createRow วิธี

สร้างแถวใหม่ในตารางที่ระบุ

พารามิเตอร์

ตั้งค่าสําหรับพารามิเตอร์ที่จําเป็นเหล่านี้

ชื่อ Type คำอธิบาย
tableName สตริง ชื่อตรรกะของตารางที่จะสร้างแถว
row object ข้อมูลแถวที่จะสร้าง

การคืนสินค้า

สัญญาที่ประกอบด้วยผลลัพธ์ของการดําเนินงาน เมื่อการดําเนินการสําเร็จ ผลลัพธ์คือค่า ID (Guid) ของแถวที่สร้างขึ้น

ตัวอย่าง createRow

// Define the row data to create new account
var row =
    {
        "name": "Sample Account",
        "creditonhold": false,
        "address1_latitude": 47.639583,
        "description": "This is the description of the sample account",
        "revenue": 5000000,
        "accountcategorycode": 1,
    }

try {
  // Create a new account record
  const newAccountId = await dataApi.createRow("account", row);
  console.log("Account created with ID: " + newAccountId);

  // Create a contact with a lookup to an account
  const newContactId = await dataApi.createRow('contact', {
    firstname: 'John',
    lastname: 'Doe',
    emailaddress1: 'john.doe@contoso.com',
    "parentcustomerid@odata.bind": `/account(${newAccountId})`, // Lookup format
  });
}
catch (error) {
  console.log(error.message);
}

deleteRow วิธี

ลบแถวจากตารางที่ระบุ

พารามิเตอร์

ตั้งค่าสําหรับพารามิเตอร์ที่จําเป็นเหล่านี้

ชื่อ Type คำอธิบาย
tableName สตริง ชื่อตรรกะของตารางที่จะลบแถว
rowId สตริง ID ของแถวที่จะลบ

การคืนสินค้า

สัญญาที่ประกอบด้วยผลลัพธ์ของการดําเนินงาน เมื่อการดําเนินการสําเร็จ จะไม่มีการคืนค่า

ตัวอย่าง deleteRow

let rowId = "5531d753-95af-e711-a94e-000d3a11e605";
try {
  await dataApi.deleteRow("account", rowId);
}
catch (error) {
  console.log(error.message);
}

getChoices วิธี

เรียกใช้ตัวเลือกสําหรับชื่อคอลัมน์ตัวเลือกที่ระบุ

พารามิเตอร์

พารามิเตอร์นี้จําเป็น

ชื่อ Type คำอธิบาย
enumName string ชื่อของคอลัมน์ตัวเลือกในรูปแบบ tablename-columnname

การคืนสินค้า

สัญญาที่ประกอบด้วยผลลัพธ์ของการดําเนินงาน เมื่อการดําเนินการสําเร็จ จะส่งกลับอาร์เรย์ของตัวเลือกตัวเลือก แต่ละตัวเลือกมีคุณสมบัติเหล่านี้:

ชื่อ Type คำอธิบาย
label สตริง ค่าป้ายชื่อที่แปลเป็นภาษาท้องถิ่นของตัวเลือก
value ตัวเลข ค่าตัวเลขของตัวเลือก

ตัวอย่าง getChoices

// Returns the accountcategorycode column options from the account table
const categoryChoices = await dataApi.getChoices("account-accountcategorycode");
// Returns the statecode column options from the contact table
const stateChoices = await dataApi.getChoices('contact-statecode');
// Returns the statuscode column options from the account table
const statusChoices = await dataApi.getChoices('account-statuscode');

queryTable วิธี

คิวรีตารางโดยใช้ตัวเลือกที่ระบุ

พารามิเตอร์

ตั้งค่าสําหรับพารามิเตอร์ที่จําเป็นเหล่านี้

ชื่อ Type คำอธิบาย
tableName string ชื่อตรรกะของตารางที่จะสอบถาม
query ตัวเลือก QueryTable ตัวเลือกสําหรับการคิวรีตาราง

ตัวเลือก QueryTable

ชื่อ Type คำอธิบาย
select string[] (แนะนํา) อาร์เรย์ของชื่อคอลัมน์ที่จะดึงข้อมูล
filter string (ไม่บังคับ) นิพจน์ตัวกรอง OData (ตัวอย่างเช่น statecode eq 0)
orderBy string (ไม่บังคับ) นิพจน์ OData orderby (ตัวอย่างเช่น name asc) createdon desc
pageSize number (ไม่บังคับ) จํานวนแถวสูงสุดที่จะแสดงต่อหนึ่งหน้า

การคืนสินค้า

สัญญาที่ประกอบด้วยผลลัพธ์ของการดําเนินงาน เมื่อการดําเนินการสําเร็จ สัญญาจะส่งคืนออบเจ็กต์ที่มีตารางข้อมูลพร้อมผลลัพธ์ที่มีคุณสมบัติเหล่านี้:

ชื่อ Type คำอธิบาย
rows Object[] อาร์เรย์ของข้อมูลแถว
hasMoreRows boolean ระบุว่ามีแถวพร้อมใช้งานมากขึ้นหรือไม่
loadMoreRows function ฟังก์ชันที่จะโหลดหน้าถัดไปของผลลัพธ์ (เลือกได้)

ตัวอย่าง queryTable

// Query tasks with options
const result = await dataApi.queryTable("task", {
    select: ["activityid", "subject", "scheduledend", "prioritycode", "statecode"],
    orderBy: "scheduledend asc",
    pageSize: 50,
    filter: "statecode eq 0"
});

// Query accounts with pagination
const pagedAccounts = await dataApi.queryTable('account', {
  select: ['name'],
  pageSize: 50,
});

console.log(`Page 1: ${pagedAccounts.rows.length} accounts`);

if (pagedAccounts.hasMoreRows && pagedAccounts.loadMoreRows) {
  const nextPage = await pagedAccounts.loadMoreRows();
  console.log(`Page 2: ${nextPage.rows.length} accounts`);
}

หมายเหตุ

Note

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

retrieveRow วิธี

ดึงข้อมูลแถวจากตารางที่ระบุโดยใช้ตัวเลือกที่ระบุ

พารามิเตอร์

ตั้งค่าสําหรับพารามิเตอร์ที่จําเป็นเหล่านี้

ชื่อ Type คำอธิบาย
tableName string ชื่อตรรกะของตารางที่จะดึงข้อมูลมา
options RetrieveRowOptions ตัวเลือกสําหรับการดึงข้อมูลแถว

RetrieveRowOptions

ชื่อ Type คำอธิบาย
id string ID (Guid) ของแถวที่จะเรียกใช้
select string[] (แนะนํา) อาร์เรย์ของชื่อคอลัมน์ที่จะดึงข้อมูล ถ้าเว้นไว้ คอลัมน์ทั้งหมดจะถูกส่งกลับ

การคืนสินค้า

สัญญาที่ประกอบด้วยผลลัพธ์ของการดําเนินงาน เมื่อการดําเนินการสําเร็จ จะส่งกลับออบเจ็กต์ที่มีข้อมูลเรกคอร์ด รวมถึงคอลัมน์ที่เลือกทั้งหมด

ตัวอย่าง retrieveRow

// Retrieve an account with all columns
const account = await dataApi.retrieveRow('account', {
  id: '30dc51e9-947d-47d8-ad48-4fc48fba4a95',
});

// Retrieve specific columns only
const contact = await dataApi.retrieveRow('contact', {
  id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
  select: ['firstname', 'lastname', '_parentcustomerid_value'],
});

updateRow วิธี

อัปเดตแถวที่มีอยู่ในตารางที่ระบุ

พารามิเตอร์

ตั้งค่าสําหรับพารามิเตอร์ที่จําเป็นเหล่านี้

ชื่อ Type คำอธิบาย
tableName สตริง ชื่อตรรกะของตารางที่จะอัปเดตแถว
rowId สตริง ID ของแถวที่จะอัปเดต
row ออบเจ็กต์ ข้อมูลแถวที่จะอัปเดต

การคืนสินค้า

สัญญาที่ประกอบด้วยผลลัพธ์ของการดําเนินงาน เมื่อการดําเนินการสําเร็จ จะไม่มีการคืนค่า

ตัวอย่าง updateRow

let rowId = "5531d753-95af-e711-a94e-000d3a11e605"

// Define the row to update a record
var row =
    {
        "name": "Updated Sample Account ",
        "creditonhold": true,
        "address1_latitude": 47.639583,
        "description": "This is the updated description of the sample account",
        "revenue": 6000000,
        "accountcategorycode": 2
    }

// update the record

try {
   await dataApi.updateRow("account", rowId, row);
}
catch (error){
  console.log(error.message);
}