Views:
TypeRead/writeAuthorAvailability
Data providerWriteFinbourneProvided with LUSID

The Lusid.Person.Writer provider enables you to write a Luminesce SQL query that either upserts or deletes one or more persons in LUSID, such as records for portfolio managers, traders, and so on. These are used for defining relationships between between persons, portfolios, portfolio groups, and legal entities. See Lusid.Relationship.

Note: The LUSID user running the query must have sufficient access control permissions to both use the provider and upsert or delete persons 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 quote 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; 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.

See also: Lusid.Person, Lusid.Relationship.Writer

Prerequisites

The representation of a person in LUSID requires an identifier to which you can attach person details and from which LUSID can generate a unique LUID, for example: 

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

The identifier comprises a key with a type of Person, a scope, and a code. The value is used to represent different persons for the same key, and together they form the unique identifier.

The Lusid.Person.Writer provider enables you to supply the displayName and description but only for an existing identifier (that is the key + value). To use the Lusid.Person.Writer you must first:

  1. Use Lusid.Property.Definition.Writer to create an identifier with a type of Person, with a ConstraintStyle of Identifier, and a Lifetime of Perpetual.
  2. Run an SQL query to link the identifier to a field you can use with the Lusid.Person.Writer provider. See How do I use Luminesce to read/write properties for LUSID entities? Once created, you can view the field in the Available Catalogues list of the Luminesce Query Editor at Lusid > Person > Writer.
  3. Write the value of the identifier to the newly added field to identify the person you want to upsert with the Lusid.Person.Writer provider.

Basic usage

@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:

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.

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

OperationMandatory fields in table of data to write
UpsertDisplayName
Description
Value for pre-defined identifier key (see Prerequisites above)
DeleteValue for pre-defined identifier key (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:

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 WriteErrorWriteErrorCode 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:

@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 alias was provided in the query.

Examples

Note: For more example Luminesce SQL queries, visit our Github repo.

Example 1: Add a person to an existing identifier key

You can upsert a name and description for a pre-defined person key by providing a value (PortMan1) for the provider field (PortManId):

@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 from an existing identifier key

You can delete the name and description from an existing identifier key by quoting a value (PortMan6) for the provider field (PortManId):

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

Example 3: Add multiple persons to existing identifier keys

You can upsert multiple names and descriptions for different pre-defined person identifier keys at the same time:

@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;