PACX ⁓ Create columns: Text
Tags: powerplatform, dataverse, opensource, tools
Published: 2024-06-15 08:55:03

We have [previously described](https://dev.to/_neronotte/pacx-create-a-table-1lgo) how to create tables easily with PACX.

Now we'll deep dive on how to fill the table we've created with columns.

I think `pacx column create` (or its alias `pacx create column`) is the most complex command we've created so far, basically due to the high number column types available in the Dataverse, and the high number of parameters available for each column type.

We started building it incrementally, one column type at time, starting from the simplest one: **text columns**

---

You can create a basic text column via

```Powershell
pacx column create --table my_table --name "Full Name"
pacx column create -t my_table -n "Full Name"
```

Those are the only 2 arguments _required_ to create a text column. PACX assumes the following conventions:

- **SchemaName** and **LogicalName** are built by
  - taking the publisher prefix of the [current default solution](https://dev.to/_neronotte/pacx-working-with-solutions-5fil) (`{prefix}`)
  - taking only letters, numbers or underscores from the specified `--name` (`{name}`)
  - contatenating `{prefix}_{name}`
- **MaxLength** is set to 100
- **StringFormat** is set to `Text`
- **RequiredLevel** is set to `None`
- **Description** is left empty
- **IsAuditEnabled** field is set to `true`

Of course you can override all those defaults using all the other optional arguments provided by the command. 

You can provide your own custom schema name, if the default generated by PACX doesn't matches your naming rules. You can do it leveraging the `schemaName` argument:

```Powershell
pacx column create --table my_table --name "Full Name" --schemaName my_table_full_name
pacx column create -t my_table -n "Full Name" -sn my_table_full_name
```

**PACX** checks if the schema name you provided matches the publisher prefix of the solution in which the field will be created. If they don't match, the command returns an error.

If you want to create the command in the context of a solution that is not the one set as default for your environment, or you don't have a default solution set for your environment, you can specify the solution via `solution` argument:

```Powershell
pacx column create --table my_table --name Code --solution my_solution_unique_name
pacx column create -t my_table -n Code -s my_solution_unique_name
```

---

The command allows you to do a lot more: if you want, for instance, to create an **AutoNumber** text field, you can simply type:

```Powershell
pacx column create --table my_table --name Code --autoNumber "C-{SEQNUM:8}"
pacx column create -t my_table -n Code -an "C-{SEQNUM:8}"
```

If you want to override the default max length:

```Powershell
pacx column create --table my_table --name Code --len 20
pacx column create -t my_table -n Code -l 20
```

If you want to create the field with audit disabled:

```Powershell
pacx column create --table my_table --name "Full Name" --audit false
pacx column create -t my_table -n "Full Name" -a false
```

If you want to provide a description for the field:

```Powershell
pacx column create --table my_table --name "Full Name" --description "The full name of the client"
pacx column create -t my_table -n "Full Name" -d "The full name of the client"
```

If you want to create different a different type of text field ([e.g. Email, TextArea, Url, Json, ...](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/reference/stringformat?view=dataverse-latest)), you can leverage the `stringFormat` argument:

```Powershell
pacx column create --table my_table --name "Full Name" --stringFormat Email
pacx column create -t my_table -n "Full Name" -sf Email
```

All those arguments can be of course mixed in a single command execution to build the field as you need. Just type

```Powershell
pacx column create --help
```

To get the list, and a quick help, on all available arguments.