Skip to content

Commit 1d54f24

Browse files
author
Abel Milash
committed
Add memo/multiline column type support with docs and tests
1 parent 5a395ec commit 1d54f24

8 files changed

Lines changed: 79 additions & 8 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ table_info = client.tables.create(
249249
#### Supported Column Types
250250
Types on the same line map to the same exact format under the hood
251251
- `"string"` or `"text"` - Single line of text
252+
- `"memo"` or `"multiline"` - Multiple lines of text (4000 character default)
252253
- `"int"` or `"integer"` - Whole number
253254
- `"decimal"` or `"money"` - Decimal number
254255
- `"float"` or `"double"` - Floating point number

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ for page in client.records.get(
402402
# Create a custom table, including the customization prefix value in the schema names for the table and columns.
403403
table_info = client.tables.create("new_Product", {
404404
"new_Code": "string",
405+
"new_Description": "memo",
405406
"new_Price": "decimal",
406407
"new_Active": "bool"
407408
})
@@ -587,7 +588,7 @@ For optimal performance in production environments:
587588
### Limitations
588589

589590
- SQL queries are **read-only** and support a limited subset of SQL syntax
590-
- Create Table supports a limited number of column types (string, int, decimal, bool, datetime, picklist)
591+
- Create Table supports the following column types: string, memo, int, decimal, float, bool, datetime, file, and picklist (Enum subclass)
591592
- File uploads are limited by Dataverse file size restrictions (default 128MB per file)
592593

593594
## Contributing

examples/advanced/walkthrough.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def _run_walkthrough(client):
119119
"new_Quantity": "int",
120120
"new_Amount": "decimal",
121121
"new_Completed": "bool",
122+
"new_Notes": "memo",
122123
"new_Priority": Priority,
123124
}
124125
table_info = backoff(lambda: client.tables.create(table_name, columns))
@@ -139,6 +140,7 @@ def _run_walkthrough(client):
139140
"new_Quantity": 5,
140141
"new_Amount": 1250.50,
141142
"new_Completed": False,
143+
"new_Notes": "This is a multiline memo field.\nIt supports longer text content.",
142144
"new_Priority": Priority.MEDIUM,
143145
}
144146
id1 = backoff(lambda: client.records.create(table_name, single_record))
@@ -191,6 +193,7 @@ def _run_walkthrough(client):
191193
"new_quantity": record.get("new_quantity"),
192194
"new_amount": record.get("new_amount"),
193195
"new_completed": record.get("new_completed"),
196+
"new_notes": record.get("new_notes"),
194197
"new_priority": record.get("new_priority"),
195198
"new_priority@FormattedValue": record.get("new_priority@OData.Community.Display.V1.FormattedValue"),
196199
},
@@ -217,9 +220,19 @@ def _run_walkthrough(client):
217220

218221
# Single update
219222
log_call(f"client.records.update('{table_name}', '{id1}', {{...}})")
220-
backoff(lambda: client.records.update(table_name, id1, {"new_Quantity": 100}))
223+
backoff(
224+
lambda: client.records.update(
225+
table_name,
226+
id1,
227+
{
228+
"new_Quantity": 100,
229+
"new_Notes": "Updated memo field.\nNow with revised content across multiple lines.",
230+
},
231+
)
232+
)
221233
updated = backoff(lambda: client.records.get(table_name, id1))
222234
print(f"[OK] Updated single record new_Quantity: {updated.get('new_quantity')}")
235+
print(f" new_Notes: {repr(updated.get('new_notes'))}")
223236

224237
# Multiple update (broadcast same change)
225238
log_call(f"client.records.update('{table_name}', [{len(ids)} IDs], {{...}})")
@@ -451,14 +464,14 @@ def _run_walkthrough(client):
451464
print("11. Column Management")
452465
print("=" * 80)
453466

454-
log_call(f"client.tables.add_columns('{table_name}', {{'new_Notes': 'string'}})")
455-
created_cols = backoff(lambda: client.tables.add_columns(table_name, {"new_Notes": "string"}))
467+
log_call(f"client.tables.add_columns('{table_name}', {{'new_Tags': 'string'}})")
468+
created_cols = backoff(lambda: client.tables.add_columns(table_name, {"new_Tags": "string"}))
456469
print(f"[OK] Added column: {created_cols[0]}")
457470

458471
# Delete the column we just added
459-
log_call(f"client.tables.remove_columns('{table_name}', ['new_Notes'])")
460-
backoff(lambda: client.tables.remove_columns(table_name, ["new_Notes"]))
461-
print(f"[OK] Deleted column: new_Notes")
472+
log_call(f"client.tables.remove_columns('{table_name}', ['new_Tags'])")
473+
backoff(lambda: client.tables.remove_columns(table_name, ["new_Tags"]))
474+
print(f"[OK] Deleted column: new_Tags")
462475

463476
# ============================================================================
464477
# 12. DELETE OPERATIONS

src/PowerPlatform/Dataverse/claude_skill/dataverse-sdk-use/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ table_info = client.tables.create(
249249
#### Supported Column Types
250250
Types on the same line map to the same exact format under the hood
251251
- `"string"` or `"text"` - Single line of text
252+
- `"memo"` or `"multiline"` - Multiple lines of text (4000 character default)
252253
- `"int"` or `"integer"` - Whole number
253254
- `"decimal"` or `"money"` - Decimal number
254255
- `"float"` or `"double"` - Floating point number

src/PowerPlatform/Dataverse/data/_odata.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,16 @@ def _attribute_payload(
13741374
"FormatName": {"Value": "Text"},
13751375
"IsPrimaryName": bool(is_primary_name),
13761376
}
1377+
if dtype_l in ("memo", "multiline"):
1378+
return {
1379+
"@odata.type": "Microsoft.Dynamics.CRM.MemoAttributeMetadata",
1380+
"SchemaName": column_schema_name,
1381+
"DisplayName": self._label(label),
1382+
"RequiredLevel": {"Value": "None"},
1383+
"MaxLength": 4000,
1384+
"FormatName": {"Value": "Text"},
1385+
"ImeMode": "Auto",
1386+
}
13771387
if dtype_l in ("int", "integer"):
13781388
return {
13791389
"@odata.type": "Microsoft.Dynamics.CRM.IntegerAttributeMetadata",

src/PowerPlatform/Dataverse/operations/tables.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def create(
8282
:type table: :class:`str`
8383
:param columns: Mapping of column schema names (with customization
8484
prefix) to their types. Supported types include ``"string"``
85-
(or ``"text"``), ``"int"`` (or ``"integer"``), ``"decimal"``
85+
(or ``"text"``), ``"memo"`` (or ``"multiline"``),
86+
``"int"`` (or ``"integer"``), ``"decimal"``
8687
(or ``"money"``), ``"float"`` (or ``"double"``), ``"datetime"``
8788
(or ``"date"``), ``"bool"`` (or ``"boolean"``), ``"file"``, and
8889
``Enum`` subclasses

tests/unit/data/test_odata_internal.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,5 +530,39 @@ def test_returns_none(self):
530530
self.assertIsNone(result)
531531

532532

533+
class TestAttributePayload(unittest.TestCase):
534+
"""Unit tests for _ODataClient._attribute_payload."""
535+
536+
def setUp(self):
537+
self.od = _make_odata_client()
538+
539+
def test_memo_type(self):
540+
"""'memo' should produce MemoAttributeMetadata with MaxLength 4000."""
541+
result = self.od._attribute_payload("new_Notes", "memo")
542+
self.assertEqual(result["@odata.type"], "Microsoft.Dynamics.CRM.MemoAttributeMetadata")
543+
self.assertEqual(result["SchemaName"], "new_Notes")
544+
self.assertEqual(result["MaxLength"], 4000)
545+
self.assertEqual(result["FormatName"], {"Value": "Text"})
546+
self.assertNotIn("IsPrimaryName", result)
547+
548+
def test_multiline_alias(self):
549+
"""'multiline' should produce identical payload to 'memo'."""
550+
memo_result = self.od._attribute_payload("new_Description", "memo")
551+
multiline_result = self.od._attribute_payload("new_Description", "multiline")
552+
self.assertEqual(multiline_result, memo_result)
553+
554+
def test_string_type(self):
555+
"""'string' should produce StringAttributeMetadata with MaxLength 200."""
556+
result = self.od._attribute_payload("new_Title", "string")
557+
self.assertEqual(result["@odata.type"], "Microsoft.Dynamics.CRM.StringAttributeMetadata")
558+
self.assertEqual(result["MaxLength"], 200)
559+
self.assertEqual(result["FormatName"], {"Value": "Text"})
560+
561+
def test_unsupported_type_returns_none(self):
562+
"""An unknown type string should return None."""
563+
result = self.od._attribute_payload("new_Col", "unknown_type")
564+
self.assertIsNone(result)
565+
566+
533567
if __name__ == "__main__":
534568
unittest.main()

tests/unit/test_tables_operations.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ def test_add_columns(self):
193193
self.client._odata._create_columns.assert_called_once_with("new_Product", columns)
194194
self.assertEqual(result, ["new_Notes", "new_Active"])
195195

196+
def test_add_columns_memo(self):
197+
"""add_columns() with memo type should pass through correctly."""
198+
self.client._odata._create_columns.return_value = ["new_Description"]
199+
200+
columns = {"new_Description": "memo"}
201+
result = self.client.tables.add_columns("new_Product", columns)
202+
203+
self.client._odata._create_columns.assert_called_once_with("new_Product", columns)
204+
self.assertEqual(result, ["new_Description"])
205+
196206
# --------------------------------------------------------- remove_columns
197207

198208
def test_remove_columns_single(self):

0 commit comments

Comments
 (0)