通过


生成页的 dataApi 参考

使用自然语言生成页面时,AI 会在 TypeScript 中创建 React 页面。 生成的页面通过选择正确的组件并确定最佳布局以及相应的业务逻辑来涵盖前端用户体验。

可以查看 和编辑生成的代码以优化输出。 数据作使用公开 dataApi 以下公共方法的对象:

方法 Description
createRow 在指定的表中创建新行。
updateRow 更新指定表中的现有行。
deleteRow 从指定的表中删除行。
retrieveRow 从具有指定选项的指定表中检索行。
queryTable 使用指定选项查询表。
getChoices 检索指定选择列名称的选项。

createRow 方法

在指定的表中创建新行。

参数

设置这些必需参数的值。

Name 类型 Description
tableName 字符串 要在其中创建行的表的逻辑名称。
row 对象 要创建的行数据。

退货

包含作结果的 承诺 。 作成功后,结果为所创建行的 ID (Guid) 值。

Example

// 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);
}

updateRow 方法

更新指定表中的现有行。

参数

设置这些必需参数的值。

Name 类型 Description
tableName 字符串 要在其中更新行的表的逻辑名称。
rowId 字符串 要更新的行的 ID。
row 物体 要更新的行数据。

退货

包含作结果的 承诺 。 作成功后,它不返回任何值。

Example

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);
}

deleteRow 方法

从指定的表中删除行。

参数

设置这些必需参数的值。

Name 类型 Description
tableName 字符串 要在其中删除行的表的逻辑名称。
rowId 字符串 要删除的行的 ID。

退货

包含作结果的 承诺 。 作成功后,它不返回任何值。

Example

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

retrieveRow 方法

使用指定的选项从指定表中检索行。

参数

设置这些必需参数的值。

Name 类型 Description
tableName string 要从中检索的表的逻辑名称
options RetrieveRowOptions 用于检索行的选项

RetrieveRowOptions

Name 类型 Description
id string 要检索的行的 ID (Guid)
select string[] (推荐)要检索的列名数组。 如果省略,则返回所有列。

退货

包含作结果的 承诺 。 作成功后,将返回包含记录数据的对象,包括所有选定的列。

Example

// 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'],
});

queryTable 方法

使用指定的选项查询表。

参数

设置这些必需参数的值。

Name 类型 Description
tableName string 要查询的表的逻辑名称
query QueryTableOptions 用于查询表的选项

QueryTableOptions

Name 类型 Description
select string[] (推荐)要检索的列名数组。
filter string (可选)OData 筛选器表达式(例如 statecode eq 0, )。
orderBy string (可选)OData orderby 表达式(例如,name asccreatedon desc)。
pageSize number (可选)每页要返回的最大行数。

退货

包含作结果的 承诺 。 作成功后,promise 将返回一个包含具有以下属性结果的数据表的对象:

Name 类型 Description
rows Object[] 行数据的数组
hasMoreRows boolean 指示是否有更多行可用
loadMoreRows function 用于加载下一页结果的函数。 (可选)

Example

// 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`);
}

注解

注释

为了获得最佳性能,请始终使用 QueryTableOptionsselect 属性限制返回的列数。

getChoices 方法

检索指定选择列名称的选项。

参数

此参数是必需的。

Name 类型 Description
enumName string 格式的选择列的名称 tablename-columnname

退货

包含作结果的 承诺 。 作成功后,它将返回选项数组。 每个选项都有以下属性:

Name 类型 Description
label 字符串 选项的本地化标签值。
value 数字 选项的数值。

Example

// 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');