---
title: "Lusid.Portfolio.CustodianAccount.Writer"
slug: "lusidportfoliocustodianaccountwriter"
updated: 2026-01-15T16:17:24Z
published: 2026-01-15T16:17:24Z
canonical: "support.lusid.com/lusidportfoliocustodianaccountwriter"
---

> ## 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.Portfolio.CustodianAccount.Writer

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

The `Lusid.Portfolio.CustodianAccount.Writer` provider enables you to write a [Luminesce SQL query](/v1/docs/understanding-the-luminesce-sql-query-syntax) that either adds, modifies or removes [custodian accounts](/v1/docs/segregating-holdings-using-custodian-accounts) from transaction portfolios.

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

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

- Upsert a custodian account; that is, create a new one if it does not already exist in the portfolio, and update certain fields and/or inlined properties if it does. This is the default operation if you omit `WriteAction`.
- Hard or soft delete a custodian account. Soft delete retains the account in the portfolio with a `Status` of `Inactive`. Hard delete removes the account from the portfolio.

**See also:** [Lusid.Portfolio.CustodianAccount](/v1/docs/lusidportfoliocustodianaccount)

## Basic usage

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

## Query parameters

`Lusid.Portfolio.CustodianAccount.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 a query like this one 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.Portfolio.CustodianAccount.Writer' and FieldType = 'Parameter';
```

## Data fields

`Lusid.Portfolio.CustodianAccount.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) | - `PortfolioScope` - `PortfolioCode` - `CustodianAccountScope` - `CustodianAccountCode` - `AccountNumber` - `AccountName` - `AccountingMethod` - `Currency` - `CustodianIdentifierTypeScope` - `CustodianIdentifierTypeCode` - `CustodianIdentifierCode` | For a list of valid `AccountingMethod` values, see [this table](/v1/docs/what-are-the-supported-tax-lot-accounting-methods-in-lusid#supported-tax-lot-accounting-methods). To see how to reference a legal entity using `CustodianIdentifierTypeScope`, `CustodianIdentifierTypeCode` and `CustodianIdentifierCode`, see [this article](/v1/docs/representing-institutions-in-lusid-using-legal-entities#understanding-userdefined-identifiers). |
| Soft delete | `'SoftDelete' as WriteAction` | - `PortfolioScope` - `PortfolioCode` - `CustodianAccountScope` - `CustodianAccountCode` |  |
| Hard delete | `'HardDelete' as WriteAction` |

To list all available fields, their data types, whether fields are considered 'main', and an explanation for each, run a query like this 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.Portfolio.CustodianAccount.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, an error code is returned. 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 custodian account to a portfolio

```sql
@data_to_write = select
        'Equities' as PortfolioScope,
        'UK' as PortfolioCode,
        'CustodianAccounts' as CustodianAccountScope,
        'JPMorgan-FIFO' as CustodianAccountCode,
        '12345678' as AccountNumber,
        'JPMorgan-FIFO' as AccountName,
        'FirstInFirstOut' as AccountingMethod,
        'GBP' as Currency,
        'InvestmentFirms' as CustodianIdentifierTypeScope,
        'InvestId' as CustodianIdentifierTypeCode,
        'Invest5' as CustodianIdentifierCode
        ;
select * from Lusid.Portfolio.CustodianAccount.Writer where ToWrite = @data_to_write;
```

### Example 2: Permanently remove a custodian account from a portfolio

You must specify `'HardDelete' as WriteAction`.

```sql
@data_to_write = select
        'HardDelete' as WriteAction,
        'Equities' as PortfolioScope,
        'UK' as PortfolioCode,
        'CustodianAccounts' as CustodianAccountScope,
        'JPMorgan-FIFO' as CustodianAccountCode
        ;
select * from Lusid.RelationalDataset.MyRDDs.Addresses.Writer where ToWrite = @data_to_write;
```
