|
| 1 | +# CREATE MESSAGE DEFINITION |
| 2 | + |
| 3 | +## Synopsis |
| 4 | + |
| 5 | +```text |
| 6 | +CREATE [ OR MODIFY ] MESSAGE DEFINITION module.Name |
| 7 | + [ FOLDER 'folder_path' ] |
| 8 | + FOR module.Entity [ AS 'ExposedName' ] { |
| 9 | + AttributeName [ AS 'ExposedName' ] [ EXAMPLE 'text' ], |
| 10 | + module.Association/module.TargetEntity [ AS 'ExposedName' ] { ... }, |
| 11 | + ... |
| 12 | + }; |
| 13 | +``` |
| 14 | + |
| 15 | +**Mendix 11.15 and later.** Below 11.15 the statement is refused; a message |
| 16 | +definition is then an entry of a |
| 17 | +[message definition collection](create-message-definition-collection.md). |
| 18 | + |
| 19 | +## Description |
| 20 | + |
| 21 | +Creates one message definition as its own document. Mendix 11.15 removed the |
| 22 | +message definition collection and stores each definition as a separate |
| 23 | +document. Studio Pro's converter turns a collection into a folder with the |
| 24 | +collection's name, holding one document per definition, so `MD_Order` with the |
| 25 | +definition `OrderMessage` becomes the folder `MD_Order` with the document |
| 26 | +`OrderMessage` in it. |
| 27 | + |
| 28 | +The body is the collection's `DEFINITION` entry: the same members, the same |
| 29 | +rules for attributes and associations, the same derived cardinality. See |
| 30 | +[CREATE MESSAGE DEFINITION COLLECTION](create-message-definition-collection.md#members). |
| 31 | + |
| 32 | +A mapping refers to the document by its two-part name: |
| 33 | + |
| 34 | +```sql |
| 35 | +mdl 1; |
| 36 | +create message definition Sales.OrderMessage |
| 37 | + folder 'Messages/MD_Order' |
| 38 | + for Sales.Order as 'Orders' { |
| 39 | + OrderId, |
| 40 | + Total as 'GrandTotal', |
| 41 | + Sales.OrderLine_Order/Sales.OrderLine as 'Lines' { Sku, Quantity }, |
| 42 | + Sales.Order_Customer/Sales.Customer { FirstName, Address example 'Kerstraat 5' } |
| 43 | + }; |
| 44 | + |
| 45 | +create import mapping Sales.IMM_Order |
| 46 | + with message definition Sales.OrderMessage |
| 47 | +{ |
| 48 | + create Sales.Order { OrderId = OrderId } |
| 49 | +}; |
| 50 | +``` |
| 51 | + |
| 52 | +On 11.15 a mapping stores this reference in `MessageDefinition2`. A script |
| 53 | +written for an older version can still name a converted definition in three |
| 54 | +parts (`Sales.MD_Order.OrderMessage`): it resolves to the document in the folder |
| 55 | +`MD_Order`, and the mapping stores the two-part name. |
| 56 | + |
| 57 | +## Editing one without restating it |
| 58 | + |
| 59 | +```sql |
| 60 | +mdl 1; |
| 61 | +alter message definition Sales.OrderMessage add member LastName in Customer; |
| 62 | +alter message definition Sales.OrderMessage set member Total as 'GrandTotal'; |
| 63 | +alter message definition Sales.OrderMessage drop member Sku in Lines; |
| 64 | +``` |
| 65 | + |
| 66 | +These are the collection's member edits, addressed by the document's two-part |
| 67 | +name. |
| 68 | + |
| 69 | +## Other statements |
| 70 | + |
| 71 | +```text |
| 72 | +LIST MESSAGE DEFINITIONS [ IN module ]; |
| 73 | +DESCRIBE MESSAGE DEFINITION module.Name; |
| 74 | +DROP MESSAGE DEFINITION [ IF EXISTS ] module.Name; |
| 75 | +``` |
| 76 | + |
| 77 | +`DESCRIBE` writes this statement, so describe and exec round-trip. Dropping a |
| 78 | +definition that a mapping still uses is refused, and the mappings are named. |
| 79 | + |
| 80 | +On 11.15 the collection statements (`CREATE`, `ALTER`, `DESCRIBE` and `DROP |
| 81 | +MESSAGE DEFINITION COLLECTION`) are refused with a hint to use this form, and |
| 82 | +`LIST MESSAGE DEFINITION COLLECTIONS` points to `LIST MESSAGE DEFINITIONS`. |
| 83 | + |
| 84 | +## See Also |
| 85 | + |
| 86 | +[CREATE MESSAGE DEFINITION COLLECTION](create-message-definition-collection.md), [CREATE IMPORT MAPPING](create-import-mapping.md), [CREATE EXPORT MAPPING](create-export-mapping.md) |
0 commit comments