テーブルと列をカスタマイズする

SDK では、 カスタム テーブル と列の作成、更新、削除 (CUD) 操作、オプションのソリューションの関連付け、およびテーブル定義の取得と一覧表示がサポートされています。

カスタム テーブルを操作するためのコード例を見てみましょう。

# Create a custom table, including the customization prefix value in the schema names for the table and columns.
table_info = client.tables.create("new_Product", {
    "new_Code": "string",
    "new_Description": "memo",
    "new_Price": "decimal",
    "new_Active": "bool"
})

# Create with custom primary column name and solution assignment
table_info = client.tables.create(
    "new_Product",
    columns={
        "new_Code": "string",
        "new_Price": "decimal"
    },
    solution="MyPublisher",  # Optional: add to specific solution
    primary_column="new_ProductName",  # Optional: custom primary column (default is "{customization prefix value}_Name")
)

# Get table information
info = client.tables.get("new_Product")
print(f"Logical name: {info['table_logical_name']}")
print(f"Entity set: {info['entity_set_name']}")

# List all tables
tables = client.tables.list()
for table in tables:
    print(table)

# Add columns to existing table (columns must include customization prefix value)
client.tables.add_columns("new_Product", {"new_Category": "string"})

# Remove columns
client.tables.remove_columns("new_Product", ["new_Category"])

# List all columns (attributes) for a table to discover schema
columns = client.tables.list_columns("account")
for col in columns:
    print(f"{col['name']} ({col.get('AttributeType')})")

# List only specific properties
columns = client.tables.list_columns(
    "account",
    select=["LogicalName", "SchemaName", "AttributeType"],
    filter="AttributeType eq 'String'",
)

# Clean up
client.tables.delete("new_Product")

Important

すべてのカスタム列名には、カスタマイズ プレフィックス値 ("new_" など) を含める必要があります。 この要件により、明示的で予測可能な名前付けが保証され、Dataverse メタデータの要件に合わせて調整されます。

カスタム テーブル メタデータの操作の詳細については、以下を参照してください。

  • create は常に GUID のリストを返します (単一入力の場合は length=1)。
  • updatedelete は、1 つのインターフェイスと複数のインターフェイスの両方の None を返します。
  • ペイロードのリストを create に渡すと、一括作成が実行され、ID の list[str] が返されます。
  • get では、レコード ID を使用した単一レコードの取得または結果セットのページングがサポートされています (列を制限する選択を優先します)。
  • レコード ID を受け取る CRUD メソッドの場合は、GUID 文字列 (ハイフネーションされた 36 文字) を渡します。 GUID を括弧で囲むことは受け入れられますが、必須ではありません。

こちらも参照ください