---
title: "Lusid.Person.Writer"
slug: "lusidpersonwriter"
updated: 2024-08-22T09:30:41Z
published: 2024-08-22T09:30:41Z
canonical: "support.lusid.com/lusidpersonwriter"
---

> ## 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.Person.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.Person.Writer` provider enables you to write a [Luminesce SQL query](/v1/docs/understanding-the-luminesce-sql-query-syntax) that either upserts or deletes one or more [person entities](/v1/docs/representing-people-in-lusid-using-person-entities) in LUSID, such as portfolio managers, traders and so on.

> **Note:** The LUSID user running the query must have sufficient [access control permissions](/v1/docs/creating-policies-to-control-access-to-providers-for-different-luminesce-end-users) to both use the provider *and* interact with person data in LUSID. This should automatically be the case if you are the domain owner.

You must construct a valid table of data to write, one person per record. `Lusid.Person.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 person entity; that is, create a person if it does not exist, and update it if it does. This is the default operation if you omit `WriteAction`.
- Delete a person entity.

**See also:** [Lusid.Person](/v1/docs/lusidperson)

## Prerequisites

> **Note**: You only need perform the operation in this section once, for both `Lusid.Person.Writer` and [Lusid.Person](/v1/docs/lusidperson).

A person entity must have at least one [user-specified identifier](/v1/docs/representing-institutions-in-lusid-using-legal-entities#understanding-identifiers) from which LUSID can generate a unique internal LUID. Consider the following JSON representation of a person entity in LUSID:

```json
"displayName": "John Doe",
"description": "A portfolio manager in US investments",
"lusidPersonId": "LUID_00003D6X",
"identifiers": {
  "Person/PortfolioManagers/ManagerId": {
     "key": "Person/PortfolioManagers/ManagerId",
     "value": {
       "labelValue": "PortMan1"
     },
     "effectiveFrom": "0001-01-01T00:00:00.0000000+00:00"
   }
}
```

It's important to note that `Lusid.Person.Writer` does not know anything about the `Person/PortfolioManagers/ManagerId` identifier out-of-the-box. For this reason, a field representing this identifier cannot be listed in the Luminesce catalog by default. In order to create a person entity, you must first:

1. Use [Lusid.Property.Definition.Writer](/v1/docs/lusidpropertydefinitionwriter) to create an identifier with a `Domain` of `Person`, a `ConstraintStyle` of `Identifier` and a `Lifetime` of `Perpetual`.
2. Run a special SQL query to ['inline' the identifier as a field](/v1/docs/how-do-i-configure-luminesce-entity-providers-to-readwrite-properties) in `Lusid.Person.Writer`, so that it appears in the catalog and can be written to. For example:

```sql
@identifiersToCatalog = values
('Person/PortfolioManagers/ManagerId', 'PortManId', True, 'An identifier for this person as a portfolio manager');

@config = select column1 as [Key], column2 as Name, column3 as IsMain, column4 as Description from @identifiersToCatalog;

select * from Sys.Admin.Lusid.Provider.Configure
where Provider = 'Lusid.Person.Writer'
and Configuration = @config;
```

You can now use `Lusid.Person.Writer` in the normal way to write values for the standard `DisplayName` and `Description` fields, and also for the newly-added identifier field (which is listed in the catalog as `PortManId`).

## Basic usage

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

## Query parameters

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

## Data fields

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

> **Note:** Do not write to the `LusidEntityId` field. It is a read-only field that can be used to retrieve the LUID that is automatically generated when you create a person.

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

| **Operation** | **Mandatory fields in table of data to write** |
| --- | --- |
| Upsert | `DisplayName` `Description` A value for the pre-defined identifier field (see *Prerequisites* above) |
| Delete | A value for the pre-defined identifier field (see *Prerequisites* above) |

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.Person.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.Person.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.

For example, the query:

```sql
@table_of_data = select 'John Smith' as DisplayName, 'A generic description for a person' as Description;
select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.Person.Writer where toWrite = @table_of_data;
```

...fails because no identifier field and value were provided in the query.

## 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 person

```sql
@table_of_data = select 'PortMan1' as PortManId, 'John Doe' as DisplayName, 'A portfolio manager in US investments' as Description;
select * from Lusid.Person.Writer where ToWrite = @table_of_data;
```

### Example 2: Remove a person

```sql
@table_of_data = select 'PortMan6' as PortManId, 'delete' as WriteAction;
select * from Lusid.Person.Writer where ToWrite = @table_of_data;
```

### Example 3: Add multiple people

```sql
@vals = values
('PortMan1', 'John Doe', 'A portfolio manager in US investments'),
('PortMan2', 'John Smith', 'A portfolio manager in UK investments'),
('PortMan3', 'Juan Perez', 'A portfolio manager in South American investments'),
('PortMan4', 'Jan Jansen', 'A portfolio manager in Dutch investments'),
('PortMan5', 'Lieschen Muller', 'A portfolio manager in German investments'),
('PortMan6', 'Jacques Martin', 'A portfolio manager in French investments');
@table_of_data = select column1 as PortManId, column2 as DisplayName, column3 as Description from @vals;
select * from Lusid.Person.Writer where ToWrite = @table_of_data;
```
