生成ページの Dataverse テーブル メソッド

dataverse テーブル行の作成、取得、更新、削除、およびクエリ選択列には、 dataApi オブジェクトのテーブル メソッドを使用します。

メソッド Description
createRow 指定したテーブルに新しい行を作成します。
deleteRow 指定したテーブルから行を削除します。
getChoices 指定した選択肢の列名の選択肢を取得します。
queryTable 指定したオプションを使用してテーブルを照会します。
retrieveRow 指定したオプションを持つ指定したテーブルから行を取得します。
updateRow 指定したテーブル内の既存の行を更新します。

createRow メソッド

指定したテーブルに新しい行を作成します。

Parameters

これらの必須パラメーターの値を設定します。

Name タイプ Description
tableName 文字列 行を作成するテーブルの論理名。
row オブジェクト 作成する行データ。

Returns

操作の結果を含む Promise 。 操作が成功すると、結果は作成された行の 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 メソッド

指定したテーブルから行を削除します。

Parameters

これらの必須パラメーターの値を設定します。

Name タイプ Description
tableName 文字列 行を削除するテーブルの論理名。
rowId 文字列 削除する行の ID。

Returns

操作の結果を含む Promise 。 操作が成功すると、値は返されません。

deleteRow の例

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

getChoices メソッド

指定した選択肢の列名の選択肢を取得します。

Parameters

このパラメーターは必須です。

Name タイプ Description
enumName string 形式の選択肢列の名前 tablename-columnname

Returns

操作の結果を含む Promise 。 操作が成功すると、選択オプションの配列が返されます。 各オプションには、次のプロパティがあります。

Name タイプ Description
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 メソッド

指定したオプションを使用してテーブルを照会します。

Parameters

これらの必須パラメーターの値を設定します。

Name タイプ Description
tableName string クエリを実行するテーブルの論理名
query QueryTableOptions テーブルに対してクエリを実行するためのオプション

QueryTableOptions

Name タイプ Description
select string[] (推奨)取得する列名の配列。
filter string (省略可能)OData フィルター式 (たとえば、 statecode eq 0)。
orderBy string (省略可能)OData orderby 式 (たとえば、 name asc、 createdon desc)。
pageSize number (省略可能)ページごとに返される行の最大数。

Returns

操作の結果を含む Promise 。 操作が成功すると、promise は次のプロパティを持つ結果を含むデータ テーブルを含むオブジェクトを返します。

Name タイプ Description
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`);
}

Remarks

Note

パフォーマンスを最大限に高めるには、 QueryTableOptionsselect プロパティを使用して返される列の数を常に制限してください。

retrieveRow メソッド

指定したオプションを使用して、指定したテーブルから行を取得します。

Parameters

これらの必須パラメーターの値を設定します。

Name タイプ Description
tableName string 取得元のテーブルの論理名
options RetrieveRowOptions 行を取得するためのオプション

RetrieveRowOptions

Name タイプ Description
id string 取得する行の ID (Guid)
select string[] (推奨)取得する列名の配列。 省略すると、すべての列が返されます。

Returns

操作の結果を含む Promise 。 操作が成功すると、選択したすべての列を含むレコード データを含むオブジェクトが返されます。

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 メソッド

指定したテーブル内の既存の行を更新します。

Parameters

これらの必須パラメーターの値を設定します。

Name タイプ Description
tableName 文字列 行を更新するテーブルの論理名。
rowId 文字列 更新する行の ID。
row Object 更新する行データ。

Returns

操作の結果を含む Promise 。 操作が成功すると、値は返されません。

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