Views:
TypeRead/writeAuthorAvailability
Data providerWriteFinbourneProvided with LUSID

The Lusid.LegalEntity.Writer provider enables you to write a Luminesce SQL query that either upserts or deletes one or more legal entities in LUSID, such as international banks, investment firms, pension companies and so on.

Note: The LUSID user running the query must have sufficient access control permissions to both use the provider and interact with legal entity 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 legal entity per record. Lusid.LegalEntity.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 legal entity; that is, create one if it does not exist, and update it if it does. This is the default operation if you omit WriteAction.
  • Delete a legal entity.

See also: Lusid.LegalEntity

Prerequisites

A legal entity must have at least one identifier from which LUSID can generate a unique internal LUID. Such an entity might be represented in JSON form in LUSID as follows : 

"displayName": "Acme Bank Inc",
"description": "A US bank",
"lusidLegalEntityId": "LUID_00003D6Y",
"identifiers": {
  "LegalEntity/InternationalBanks/BankId": {
     "key": "LegalEntity/InternationalBanks/BankId",
     "value": {
       "labelValue": "AcmeInc"
     },
     "effectiveFrom": "0001-01-01T00:00:00.0000000+00:00"
   }
}

It's important to note that Lusid.LegalEntity.Writer cannot create the identifier key (in this case, LegalEntity/InternationalBanks/BankId). For this reason, a field representing the identifier key cannot by default be listed in the catalog for the provider. In order to create a legal entity, therefore, you must first:

  1. Use Lusid.Property.Definition.Writer to create an identifier key with a Domain of LegalEntity, a ConstraintStyle of Identifier and a Lifetime of Perpetual.
  2. Run a special SQL query to 'inline' the identifier key as a field in Lusid.LegalEntity.Writer, so that it appears in the catalog and can be written to. For example:
    @identifiersToCatalog = values
    ('LegalEntity/InternationalBanks/BankId', '_identifier', 'IntBankId');
    @outputFromSaveAs = use Sys.Admin.File.SaveAs with @identifiersToCatalog
    --path=/config/lusid/factories/
    --type:Csv
    --fileNames
    legalentityproviderfactory
    enduse;
    select * from @outputFromSaveAs;

You can now use Lusid.LegalEntity.Writer in the normal way to write values for the standard DisplayName and Description fields, and also for the newly-added identifier key field (which in this case will be listed in the catalog as IntBankId).

Basic usage

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

Query parameters

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

Data fields

Lusid.LegalEntity.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 legal entity.

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
A value for the pre-defined identifier key (see Prerequisites above)
DeleteA value for the 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.LegalEntity.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.LegalEntity.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 'Acme Bank Inc' as DisplayName, 'A US bank' as Description;
select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.LegalEntity.Writer where toWrite = @table_of_data;

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

Examples

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

Example 1: Add a legal entity to an existing identifier key

You can upsert a name, description and value (AcmeInc) for a pre-defined identifier key field (IntBankId):

@table_of_data = select 'AcmeInc' as IntBankId, 'Acme Bank Inc' as DisplayName, 'A US bank' as Description;
select * from Lusid.LegalEntity.Writer where ToWrite = @table_of_data;

Example 2: Remove a legal entity from an existing identifier key

You can delete the name and description from an existing identifier key by quoting a value (AcmeInc) for a pre-defined identifier key field (IntBankId):

@table_of_data = select 'AcmeInc' as IntBankId, 'delete' as WriteAction;
select * from Lusid.LegalEntity.Writer where ToWrite = @table_of_data;

Example 3: Add multiple legal entities to existing identifier keys

@vals = values
('AcmeInc', 'Acme Bank Inc', 'A US bank'),
('AcmeLtd', 'Acme Bank Ltd', 'A UK bank'),
('AcmeSarl', 'Acme Bank SaRL', 'A French bank'),
('AcmeGmbh', 'Acme Bank GmbH', 'A German bank');
@table_of_data = select column1 as IntBankId, column2 as DisplayName, column3 as Description from @vals;
select * from Lusid.LegalEntity.Writer where ToWrite = @table_of_data;