Views:
TypeRead/writeAuthorAvailability
Data providerWriteFINBOURNEProvided with LUSID

Providing you have sufficient access control permissions, the Lusid.ChartOfAccounts.Account.Writer provider enables you to write a Luminesce SQL query that either adds or deletes general ledger accounts to or from an existing chart of accounts (CoA). See how to create a CoA.

Note: By default, Lusid.ChartOfAccounts.Account.Writer cannot add properties to accounts. To do this, you must first configure Lusid.ChartOfAccounts.Account.Writer to 'inline' properties. See how to do this.

You must construct a valid table of data to write, one account per record. Lusid.ChartOfAccounts.Account.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 account; that is, create one if the account code does not already exist in the CoA, and update certain fields and/or inlined properties if it does. This is the default operation if you omit WriteAction.
  • Hard or soft delete a account. Soft delete retains the account in the CoA with a Status of Inactive. Hard delete removes the account from the CoA.

See also: Lusid.ChartOfAccounts.Account

Basic usage

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

Query parameters

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

Data fields

Lusid.ChartOfAccounts.Account.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:

OperationSpecify using...Mandatory fieldsNotes
Upsert'Upsert' as WriteAction (or omit)ChartOfAccountsScope
ChartOfAccountsCode
AccountCode
Control
(either Manual or System)
Type (either Asset, Liabilities, Income, Expense, Capital or Revenue)
You can update the Control, Type and Description fields of an existing account, and any inlined properties.
Soft delete'SoftDelete' as WriteActionChartOfAccountsScope
ChartOfAccountsCode
AccountCode
 
Hard delete'HardDelete' as WriteAction

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.ChartOfAccounts.Account.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.ChartOfAccounts.Account.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: Create a single account

Upsert is the default operation if you omit the WriteAction field.

@data_to_write = select 'Abor' as ChartOfAccountsScope, 'Standard' as ChartOfAccountsCode,
'1-Investments' as AccountCode, 'Asset' as [Type], 'Manual' as Control;
select * from Lusid.ChartOfAccounts.Account.Writer where ToWrite = @data_to_write;

Example 2: Create multiple accounts

@accounts = values
('1-Investments', 'Asset', 'This is an account for investments'),
('2-Cash', 'Liabilities', 'This is an account for cash'),
('3-Subscriptions', 'Revenue', 'This is an account for subscriptions')
;
@data_to_write = select 'Abor' as ChartOfAccountsScope, 'Standard' as ChartOfAccountsCode,
column1 as AccountCode, column2 as [Type], 'Manual' as Control, column3 as Description from @accounts;
select * from Lusid.ChartOfAccounts.Account.Writer where ToWrite = @data_to_write;

Example 3: Hard delete a account

@data_to_write = select 'Abor' as ChartOfAccountsScope, 'Standard' as ChartOfAccountsCode,
'1-Investments' as AccountCode, 'HardDelete' as WriteAction;
select * from Lusid.ChartOfAccounts.Account.Writer where ToWrite = @data_to_write;