Views:
TypeRead/writeAuthorAvailability
Data providerWriteFINBOURNEProvided with LUSID

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

You must construct a valid table of data to write, one posting rule per record. Lusid.PostingModule.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 posting rules in the posting module. To retain existing posting rules, include them in your query.
  • The order in which posting rules are specified in a posting module is significant; LUSID uses the first matching posting rule found. You can use the RulePriority field to set the order of posting rules.

See also: Lusid.PostingModule.Rule

Basic usage

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

Query parameters

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

Data fields

Lusid.PostingModule.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
PostingModuleCode
RuleId
AccountCode
RuleFilter

RuleId must be unique within the posting module.
 

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

For information on the syntax of RuleFilter expressions, see this article. 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 posting module has more than one posting rule you should specify a different, postive whole number for each. Posting 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.PostingModule.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.PostingModule.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 posting rule

Any existing rules in the posting module are replaced.

@data_to_write = select 'DailyNAV' as PostingModuleCode, 'Abor' as ChartOfAccountsScope, 'Standard' as ChartOfAccountsCode,
'rule_01' as RuleId, '1-Investments' as AccountCode, 'HoldType eq ''P''' as RuleFilter;
select * from Lusid.PostingModule.Rule.Writer where ToWrite = @data_to_write;

Example 2: Add multiple posting rules in a particular order

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

@posting_rules = values
('rule_01', '1-Investments', 'HoldType eq ''P''', 1),
('rule_02', '2-Cash', 'HoldType eq ''C''', 2),
('rule_03', '3-Subscriptions', 'EconomicBucket startswith ''CA'' and Properties[Instrument/BBG/Country] exists', 3)
;
@data_to_write = select 'DailyNAV' as PostingModuleCode, 'Abor' as ChartOfAccountsScope, 'Standard' as ChartOfAccountsCode,
column1 as RuleId, column2 as AccountCode, column3 as RuleFilter, column4 as RulePriority from @posting_rules;

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