Views:
TypeRead/writeAuthorAvailability
Data providerWriteFINBOURNEProvided with LUSID

Providing you have sufficient access control permissions, the Lusid.CleardownModule.Rule.Writer provider enables you to write a Luminesce SQL query that sets cleardown rules for an existing cleardown module. See how to create a cleardown module.

You must construct a valid table of data to write, one cleardown rule per record. Lusid.CleardownModule.Rule.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.

Note the following:

  • Your query replaces any existing cleardown rules in the cleardown module. To retain existing cleardown rules, include them in your query.
  • The order in which cleardown rules are specified in a cleardown module is significant; LUSID uses the first matching cleardown rule found. You can use the RulePriority field to set the order of cleardown rules.

See also: Lusid.CleardownModule.Rule

Basic usage

@table_of_data = <select-statement>;
select * from Lusid.CleardownModule.Rule.Writer where ToWrite = @table_of_data;

Query parameters

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

Data fields

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

The following fields are mandatory to include in the table of data:

Mandatory fieldsNotes
ChartOfAccountsScope
ChartOfAccountsCode
CleardownModuleCode
RuleId
GeneralLedgerAccountCode
RuleFilter

RuleId must be unique within the cleardown module.
 

GeneralLedgerAccountCode must be a general ledger account registered with the parent chart of accounts (CoA).
 

The syntax of and allowed values for a RuleFilter expression are documented here. Note each ' character encapsulating a string value must be escaped by an additional ' character in Luminesce, so for example select 'HoldType eq ''P''' as RuleFilter.
 

RulePriority defaults to 0.00 but if your cleardown module has more than one cleardown rule you should specify a different positive whole number for each. Cleardown rules with lower numbers take precedence and are evaluated earlier.

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.CleardownModule.Rule.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.CleardownModule.Rule.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.

Examples

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

Example 1: Add a single cleardown rule

Any existing rules in the cleardown module are replaced.

@data_to_write = select 'DailyNAV' as CleardownModuleCode, 'Abor' as ChartOfAccountsScope, 'Standard' as ChartOfAccountsCode,
'rule_01' as RuleId, '1-Investments' as AccountCode, 'Account.Code startswith ''200''' as RuleFilter;

select * from Lusid.CleardownModule.Rule.Writer where ToWrite = @data_to_write;

Example 2: Add multiple cleardown rules in a particular order

The RulePriority field determines the order in which cleardown rules are evaluated; LUSID uses the first matching cleardown rule found. Lower numbers take precedence and are evaluated earlier.

@cleardown_rules = values
('rule_01', '1-Investments', 'Account.Code startswith ''200''', 1),
('rule_02', '2-Cash', 'Account.Type in ''Income'',''Expense'',''Revenue''', 2),
('rule_03', '3-Subscriptions', 'Properties[Account/MyScope/Cleardown] exists and Properties[Abor/MyScope/Region] eq ''EMEA''', 3)
;
@data_to_write = select 'DailyNAV' as CleardownModuleCode, 'Abor' as ChartOfAccountsScope, 'Standard' as ChartOfAccountsCode,
column1 as RuleId, column2 as AccountCode, column3 as RuleFilter, column4 as RulePriority from @cleardown_rules;

select * from Lusid.CleardownModule.Rule.Writer where ToWrite = @data_to_write;