Type | Read/write | Author | Availability |
Write | Finbourne | Provided 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
Note: You only need perform the operation in this section once, for both
Lusid.LegalEntity.Writer
and Lusid.LegalEntity.
A legal entity must have at least one user-specified identifier from which LUSID can generate a unique internal LUID. Consider the following JSON representation of a legal entity in LUSID:
"displayName": "Acme Bank Inc",
"description": "An international 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
does not know anything about the LegalEntity/InternationalBanks/BankId
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 legal entity, you must first:
Use Lusid.Property.Definition.Writer to create an identifier with a
Domain
ofLegalEntity
, aConstraintStyle
ofIdentifier
and aLifetime
ofPerpetual
.Run a special SQL query to 'inline' the identifier as a field in
Lusid.LegalEntity.Writer
, so that it appears in the catalog and can be written to. For example:@identifiersToCatalog = values ('LegalEntity/InternationBanks/BankId', 'IntBankId', True, 'An identifier for this legal entity as an international bank'); @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.LegalEntity' and Configuration = @config;
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 field (which is 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 the following:
Do not write to the
LusidEntityId
field. It can be used to retrieve the LUID that is automatically generated when you create a legal entity.You can write to the
LEI
field if you want to populate theLegalEntity/default/LEI
system property.
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 |
|
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:
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 WriteError
, WriteErrorCode
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 field 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
@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
@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
@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;