Skip to content

Commit fa9dac0

Browse files
committed
Add extended table metadata retrieval and models for columns and option sets
- Implemented methods to fetch detailed metadata for tables, including columns and relationships. - Introduced `ColumnMetadata`, `OptionItem`, and `OptionSetInfo` models to represent column and option set data structures. - Updated `get` method in `TableOperations` to support optional parameters for including columns and relationships in the response. - Enhanced tests to cover new functionality and ensure backward compatibility. This update improves the SDK's ability to interact with Dataverse metadata, providing richer data for developers.
1 parent c61c94a commit fa9dac0

8 files changed

Lines changed: 1306 additions & 4 deletions

File tree

.claude/skills/dataverse-sdk-use/SKILL.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,63 @@ for table in tables:
223223
print(table)
224224
```
225225

226+
#### Get Extended Table Metadata
227+
```python
228+
# Get table with column metadata
229+
info = client.tables.get("account", include_columns=True)
230+
for col in info["columns"]:
231+
print(f"{col.logical_name} ({col.attribute_type})")
232+
233+
# Get table with relationship metadata
234+
info = client.tables.get("account", include_relationships=True)
235+
236+
# Get specific entity properties
237+
info = client.tables.get("account", select=["DisplayName", "Description"])
238+
```
239+
240+
#### List Columns
241+
```python
242+
from PowerPlatform.Dataverse.models.metadata import ColumnMetadata
243+
244+
columns = client.tables.get_columns("account")
245+
for col in columns:
246+
print(f"{col.schema_name}: {col.attribute_type} (required: {col.required_level})")
247+
248+
# Filter to specific column types (OData syntax, fully-qualified enum)
249+
picklists = client.tables.get_columns(
250+
"account",
251+
filter="AttributeType eq Microsoft.Dynamics.CRM.AttributeTypeCode'Picklist'",
252+
)
253+
```
254+
255+
#### Get Single Column
256+
```python
257+
col = client.tables.get_column("account", "emailaddress1")
258+
if col:
259+
print(f"Type: {col.attribute_type}, Required: {col.required_level}")
260+
```
261+
262+
#### Get Column Options (Picklist/Choice Values)
263+
```python
264+
from PowerPlatform.Dataverse.models.metadata import OptionSetInfo
265+
266+
options = client.tables.get_column_options("account", "accountcategorycode")
267+
if options:
268+
for opt in options.options:
269+
print(f" Value={opt.value}, Label={opt.label}")
270+
```
271+
272+
#### List Table Relationships
273+
```python
274+
# All relationships
275+
rels = client.tables.list_relationships("account")
276+
277+
# Specific type: "one_to_many" / "1:N", "many_to_one" / "N:1", "many_to_many" / "N:N"
278+
rels = client.tables.list_relationships("account", relationship_type="one_to_many")
279+
for rel in rels:
280+
print(f"{rel['SchemaName']}: {rel.get('ReferencingEntity')}")
281+
```
282+
226283
#### Delete Tables
227284
```python
228285
client.tables.delete("new_Product")

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,40 @@ client.tables.remove_columns("new_Product", ["new_Category"])
309309
client.tables.delete("new_Product")
310310
```
311311

312+
```python
313+
# Get extended table metadata with columns
314+
info = client.tables.get("account", include_columns=True)
315+
for col in info["columns"]:
316+
print(f"{col.logical_name} ({col.attribute_type})")
317+
318+
# Get extended table metadata with relationships
319+
info = client.tables.get("account", include_relationships=True)
320+
for rel in info.get("one_to_many_relationships", []):
321+
print(rel["SchemaName"])
322+
323+
# Get specific entity properties
324+
info = client.tables.get("account", select=["DisplayName", "Description"])
325+
326+
# List all columns of a table
327+
columns = client.tables.get_columns("account")
328+
for col in columns:
329+
print(f"{col.schema_name}: {col.attribute_type} (required: {col.required_level})")
330+
331+
# Get a specific column's metadata
332+
col = client.tables.get_column("account", "emailaddress1")
333+
if col:
334+
print(f"Type: {col.attribute_type}, Required: {col.required_level}")
335+
336+
# Get picklist/choice column options
337+
options = client.tables.get_column_options("account", "accountcategorycode")
338+
if options:
339+
for opt in options.options:
340+
print(f" {opt.value}: {opt.label}")
341+
342+
# List relationships for a table
343+
rels = client.tables.list_relationships("account", relationship_type="one_to_many")
344+
```
345+
312346
> **Important**: All custom column names must include the customization prefix value (e.g., `"new_"`).
313347
> This ensures explicit, predictable naming and aligns with Dataverse metadata requirements.
314348

src/PowerPlatform/Dataverse/common/constants.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,30 @@
2929

3030
CASCADE_BEHAVIOR_RESTRICT = "Restrict"
3131
"""Prevent the referenced table record from being deleted when referencing table records exist."""
32+
33+
# AttributeMetadata derived type OData identifiers
34+
# Used when casting Attributes collection to a specific derived type in Web API URLs
35+
ODATA_TYPE_PICKLIST_ATTRIBUTE = "Microsoft.Dynamics.CRM.PicklistAttributeMetadata"
36+
ODATA_TYPE_BOOLEAN_ATTRIBUTE = "Microsoft.Dynamics.CRM.BooleanAttributeMetadata"
37+
ODATA_TYPE_MULTISELECT_PICKLIST_ATTRIBUTE = "Microsoft.Dynamics.CRM.MultiSelectPicklistAttributeMetadata"
38+
ODATA_TYPE_STRING_ATTRIBUTE = "Microsoft.Dynamics.CRM.StringAttributeMetadata"
39+
ODATA_TYPE_INTEGER_ATTRIBUTE = "Microsoft.Dynamics.CRM.IntegerAttributeMetadata"
40+
ODATA_TYPE_DECIMAL_ATTRIBUTE = "Microsoft.Dynamics.CRM.DecimalAttributeMetadata"
41+
ODATA_TYPE_DOUBLE_ATTRIBUTE = "Microsoft.Dynamics.CRM.DoubleAttributeMetadata"
42+
ODATA_TYPE_MONEY_ATTRIBUTE = "Microsoft.Dynamics.CRM.MoneyAttributeMetadata"
43+
ODATA_TYPE_DATETIME_ATTRIBUTE = "Microsoft.Dynamics.CRM.DateTimeAttributeMetadata"
44+
ODATA_TYPE_MEMO_ATTRIBUTE = "Microsoft.Dynamics.CRM.MemoAttributeMetadata"
45+
ODATA_TYPE_FILE_ATTRIBUTE = "Microsoft.Dynamics.CRM.FileAttributeMetadata"
46+
47+
# Attribute type code values returned in the AttributeType property of attribute metadata
48+
ATTRIBUTE_TYPE_PICKLIST = "Picklist"
49+
ATTRIBUTE_TYPE_BOOLEAN = "Boolean"
50+
ATTRIBUTE_TYPE_STRING = "String"
51+
ATTRIBUTE_TYPE_INTEGER = "Integer"
52+
ATTRIBUTE_TYPE_DECIMAL = "Decimal"
53+
ATTRIBUTE_TYPE_DOUBLE = "Double"
54+
ATTRIBUTE_TYPE_MONEY = "Money"
55+
ATTRIBUTE_TYPE_DATETIME = "DateTime"
56+
ATTRIBUTE_TYPE_MEMO = "Memo"
57+
ATTRIBUTE_TYPE_LOOKUP = "Lookup"
58+
ATTRIBUTE_TYPE_UNIQUEIDENTIFIER = "Uniqueidentifier"

0 commit comments

Comments
 (0)