---
title: "Lusid.ChartOfAccounts.Writer"
slug: "lusidchartofaccountswriter"
updated: 2024-08-22T09:15:28Z
published: 2024-08-22T09:15:28Z
canonical: "support.lusid.com/lusidchartofaccountswriter"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://support.lusid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Lusid.ChartOfAccounts.Writer

| **Type** | **Read/write** | **Author** | **Availability** |
| --- | --- | --- | --- |
| [Data provider](/v1/docs/what-are-a-data-provider-and-a-direct-provider) | Write | FINBOURNE | Provided with LUSID |

Providing you have sufficient [access control permissions](/v1/docs/creating-policies-to-control-access-to-providers-for-different-luminesce-end-users), the `Lusid.ChartOfAccounts.Writer` provider enables you to write a [Luminesce SQL query](/v1/docs/understanding-the-luminesce-sql-query-syntax) that either creates or deletes [chart of accounts](/v1/docs/how-do-i-create-a-chart-of-accounts) (CoA) entities in LUSID.

> [!NOTE]
> **Note**: By default, `Lusid.ChartOfAccounts.Writer` cannot add properties to CoA entities. To do this, you must first configure `Lusid.ChartOfAccounts.Writer` to 'inline' properties. [See how to do this](/v1/docs/how-do-i-configure-luminesce-entity-providers-to-readwrite-properties).

You must construct a valid table of data to write, one CoA per record. `Lusid.ChartOfAccounts.Writer` lists the fields (columns) available to populate with values for each record, and has a set of parameters to help you construct a valid table.

Your query can use the `WriteAction` field to perform one of the following operations:

- Upsert a CoA; that is, create a CoA if it does not already exist, and update just inlined properties if it does. Note it is not currently possible to update the core data fields of an existing CoA. This is the default operation if you omit `WriteAction`.
- Delete a CoA.

Once you have created a CoA, you can add [general ledger accounts](/v1/docs/lusidchartofaccountsaccountwriter), [posting modules](/v1/docs/lusidpostingmodule), [cleardown modules](/v1/docs/lusidcleardownmodule) and [general ledger profiles](/v1/docs/lusidgeneralledgerprofilewriter) to it.

**See also:** [Lusid.ChartOfAccounts](/v1/docs/lusidchartofaccounts)

## Basic usage

```sql
@table_of_data = <select-statement>;
select * from Lusid.ChartOfAccounts.Writer where toWrite = @table_of_data;
```

## Query parameters

`Lusid.ChartOfAccounts.Writer` has parameters that help you construct a valid table of data to write.

> [!NOTE]
> **Note:** The `ToWrite` parameter is mandatory and used to actually write the table of data into LUSID.

To list available parameters, their data types, default values, and an explanation for each, run the following query using a [suitable tool](/v1/docs/what-tools-are-available-to-write-luminesce-queries):

```sql
select FieldName, DataType, ParamDefaultValue, Description from Sys.Field where TableName = 'Lusid.ChartOfAccounts.Writer' and FieldType = 'Parameter';
```

## Data fields

`Lusid.ChartOfAccounts.Writer` lists the fields you can populate in your table of data to write.

Depending on the operation you want to perform, the following fields are mandatory to include in the table of data:

| **Operation** | **Specify using...** | **Mandatory fields** | **Notes** |
| --- | --- | --- | --- |
| Upsert | `'Upsert' as WriteAction` (or omit) | `ChartOfAccountsScope` `ChartOfAccountsCode` | You can only update inlined properties of an existing CoA, not core data fields such as `Description` and `DispayName`. |
| Insert | `'Insert' as WriteAction` |  |
| Update | `'Update' as WriteAction` | You can only update inlined properties of an existing CoA, not core data fields such as `Description` and `DisplayName`. |
| Delete | `'Delete' as WriteAction` |  |

To list all available fields, their data types, whether fields are considered 'main', and an explanation for each, run the following query using a [suitable tool](/v1/docs/what-tools-are-available-to-write-luminesce-queries):

```sql
select FieldName, DataType, IsMain, IsPrimaryKey, SampleValues, Description from Sys.Field where TableName = 'Lusid.ChartOfAccounts.Writer' and FieldType = 'Column';
```

## Write errors

We recommend examining the results of every write query using one or more of the `WriteError`, `WriteErrorCode` and `WriteErrorDetail` fields.

For each record in the table of data to write, `Lusid.ChartOfAccounts.Writer` returns an error code. If the operation is successful, the error code is `0`. If unsuccessful, a positive error code and explanation help you discover why LUSID considers the operation invalid.

## Examples

> **Note:** For more example Luminesce SQL queries, visit our [Github repo](https://github.com/finbourne/luminesce-examples/tree/master/examples/lusid/abor).

### Example 1: Create a CoA

Upsert is the default operation if you omit the `WriteAction` field.

```sql
@data_to_write = select 'Abor' as ChartOfAccountsScope, 'Standard' as ChartOfAccountsCode;
select * from Lusid.ChartOfAccounts.Writer where ToWrite = @data_to_write;
```

### Example 2: Create multiple CoAs in the same scope

```sql
@@scope = select 'Abor';
@CoAs = values
('Standard', 'Standard CoA', 'This is a CoA for standard reporting'),
('EoY', 'End of year CoA', 'This is a CoA for end of year reporting'),
('Q', 'Quarterly CoA', 'This is a CoA for quarterly reporting')
;
@data_to_write = select @@scope as ChartOfAccountsScope, column1 as ChartOfAccountsCode, column2 as DisplayName, column3 as Description from @CoAs;
select * from Lusid.ChartOfAccounts.Writer where ToWrite = @data_to_write;
```

### Example 3: Delete a CoA

```sql
@data_to_write = select 'Abor' as ChartOfAccountsScope, 'Standard' as ChartOfAccountsCode, 'Delete' as WriteAction;
select * from Lusid.ChartOfAccounts.Writer where ToWrite = @data_to_write;
```
