---
title: "Lusid.CleardownModule.Writer"
slug: "lusidcleardownmodulewriter"
updated: 2024-08-21T08:19:31Z
published: 2024-08-21T08:19:31Z
canonical: "support.lusid.com/lusidcleardownmodulewriter"
---

> ## 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.CleardownModule.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.CleardownModule.Writer` provider enables you to write a [Luminesce SQL query](/v1/docs/understanding-the-luminesce-sql-query-syntax) that either adds or removes [cleardown module(s)](/v1/docs/how-do-i-add-a-cleardown-module-with-cleardown-rules-to-a-chart-of-accounts) to or from an existing chart of accounts (CoA). [See how to create a CoA](/v1/docs/lusidchartofaccountswriter).

You must construct a valid table of data to write, one cleardown module per record. `Lusid.CleardownModule.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 cleardown module; that is, add one to a CoA if it does not exist, and update certain fields if it does. This is the default operation if you omit `WriteAction`.
- Delete a cleardown module; that is, remove it from a CoA.

Once you have added a cleardown module to a CoA, you can [set cleardown rules for it](/v1/docs/lusidcleardownmodulerulewriter).

**See also:** [Lusid.CleardownModule](/v1/docs/lusidcleardownmodule)

## Basic usage

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

## Query parameters

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

> **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.CleardownModule.Writer' and FieldType = 'Parameter';
```

## Data fields

`Lusid.CleardownModule.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) | `CleardownModuleCode` `ChartOfAccountsScope` `ChartOfAccountsCode` `DisplayName` | `Status` defaults to `Active` if omitted. The alternative value is `Inactive`. |
| Insert | `'Insert' as WriteAction` |
| Update | `'Update' as WriteAction` | `CleardownModuleCode` `ChartOfAccountsScope` `ChartOfAccountsCode` `DisplayName` `Status` | You can change the `Status`, `DisplayName` and `Description` of an existing cleardown module. |
| Delete | `'Delete' as WriteAction` | `CleardownModuleCode` `ChartOfAccountsCode` `ChartOfAccountsScope` |  |

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.CleardownModule.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.CleardownModule.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).

### Example 1: Add a cleardown module to a CoA

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

```sql
@data_to_write = select 'DailyNAV' as CleardownModuleCode, 'Abor' as ChartOfAccountsScope, 
'Standard' as ChartOfAccountsCode, 'Daily NAV' as DisplayName, 'Cleardown module for daily NAV' as Description;

select * from Lusid.CleardownModule.Writer where ToWrite = @data_to_write;
```

### Example 2: Add multiple cleardown modules to a CoA

```sql
@@scope = select 'Abor';

@modules = values
('DailyNAV', 'Daily NAV', 'Cleardown module for daily NAV'),
('EoYNAV', 'End of year NAV', 'Cleardown module for end of year NAV'),
('QNav', 'Quarterly NAV', 'Cleardown module for quarterly NAV')
;
@data_to_write = select column1 as CleardownModuleCode, @@scope as ChartOfAccountsScope,
'Standard' as ChartOfAccountsCode, column2 as DisplayName, column3 as Description from @modules;

select * from Lusid.CleardownModule.Writer where ToWrite = @data_to_write;
```

### Example 3: Remove a cleardown module from a CoA

```sql
@data_to_write = select 'DailyNAV' as CleardownModuleCode, 'Abor' as ChartOfAccountsScope,
'Standard' as ChartOfAccountsCode, 'Delete' as WriteAction;

select * from Lusid.CleardownModule.Writer where ToWrite = @data_to_write;
```
