PACX ⁓ Create a table
Tags: powerplatform, dataverse, opensource, tools
Published: 2024-06-10 17:34:43

[We have previously talked about what does it mean to manually manipulate the Dataverse data model](https://dev.to/_neronotte/pacx-data-model-manipulation-579e), and the benefits of data model scripting.

We'll now deep dive on what it means to create tables, columns and relations via PACX.

---

[Creating a table with PACX](https://github.com/neronotte/Greg.Xrm.Command/wiki/pacx-table-create) is quite easy. 

As a **prerequisite**, you must connect to a Dataverse environment via `pacx auth create` or `pacx auth select`, and optionally you can select a default solution via `pacx solution setDefault`. 

Then you can just type

```Powershell
pacx table create --name "My Table"
```

to create a new table named "My Table" in the context of the solution set as default via `pacx solution setDefault`. If no solution is set as default, the `--solution` argument is mandatory. 

The table schema name will be automatically generated extrapolating only chars, numbers and underscores from the display name, setting them lowercase, prefixed with the solution's publisher prefix. 

In this case, if the publisher prefix is `greg`, the generated schema name will be `greg_mytable`.

> The command can be also run using the alias `pacx create table`

The following default conventions apply automatically:

- **DisplayCollectionName** (aka the plural name of the entity) can be specified using `--plural` argument. If not specified, is inferred automatically pluralizing the display name (automatic pluralization is done via [Pluralize.NET](https://github.com/sarathkcm/Pluralize.NET), and is currently supported only if base language is English - 1033).
- **Description** can be specified using `--description` argument, otherwise is left empty.
- **SchemaName** can be specified using `--schemaName` argument, otherwise is inferred from the display name as described above.
- **OwnershipType** can be specified using `--ownership` argument, otherwise is set as `UserOwned`.
- **IsActivity** by default is `false`, can be changed via `--isActivity` argument
- **IsAvailableOffline** by default is `false` unless the table is an activity table, or the `--offline` argument is specified
- **IsValidForQueue** by default is `false` unless the table is an activity table, or the `--queue` argument is specified
- **IsConnectionsEnabled** by default is `false` unless the table is an activity table, or the `--connection` argument is specified
- **HasNotes** by default is `false` unless the table is an activity table, or the `--notes` argument is specified
- **HasFeedback** by default is `false` unless the table is an activity table, or the `--feedback` argument is specified
- **IsAuditEnabled** by default is `true`, but can be overridden via `--audit false` argument

About the table **primary attribute**:

- You can set it as an **Autonumber** field via `--primaryAttributeAutoNumberFormat` argument (`-paan`). If not specified, it is assumed to be plain text.
- The **display name** 
  - if the table is an activity, is fixed to `Subject`
  - otherwise, it can be specified via `--primaryAttributeName` (`-pan`) argument. 
  - if not specified
    - if the the primary attribute is an autonumber, it's set by default to `Code`
    - otherwise it's set to `Name`
- The **requirement level**
  - can be specified via `--primaryAttributeRequiredLevel` (`-par`). 
  - if not specified
    - if it's an autonumber, it's set by default to `None`
    - otherwise it's set by default to `ApplicationRequired`
- The **max length** is _100_ by default, unless specified via `--primaryAttributeMaxLength` (`-palen`) argument
- The description can be set via `--primaryAttributeDescription` argument (`-pad`). If not specified, is left empty

[Take a look to the official documentation](https://github.com/neronotte/Greg.Xrm.Command/wiki/pacx-table-create) to get the list of all the command arguments.

Once created, you can use the following command

```Powershell
pacx table exportMetadata --table greg_mytable -r
```

To [generate and open a JSON representation](https://github.com/neronotte/Greg.Xrm.Command/wiki/pacx-table-exportMetadata) of the table metadata. 

---

Hope this can be helpful to start using PACX in your daily activities. In the next articles we'll deep dive on how to work with _columns_.