Good day, dear readers of our blog! Today I want to tell you, using a real example, how
use the ACS functions Array and JoinStrings. In an article about

there was a little mention of how to work with
on the bookmark
, has also already been explained as
using the "Resources" tab. Today we will once again pay attention to these
bookmarks in light of our topic.

Appearance of an example 1C report using two ACS functions Array And ConnectRows next:

Statement of the problem for using the ACS functions Array and JoinStrings

Task: You need to insert all sales numbers for one product into one cell.

Something like: nomenclature | quantity | 001, 002, etc. |

We will use a request to the accumulation register “Realization of TMZ”.

CHOOSE
Implementation of TMZ. Registrar. Number,
Implementation of TMZ. Nomenclature,
Implementation of TMZ. Registrar,
Implementation of TMZ. QuantityTurnover
FROM
Accumulation Register. Implementation of TMZ. Revolutions
(, , Registrar, ) HOW TO Implement TMZ

The accumulation register “Realization of TMZ” exists both in the Accounting configuration and in the Trade Enterprise Management (UTP) configuration. Find out how to configure the USP in the “Nomenclature” directory element. Therefore, after downloading, you can run this report in both configurations to check its functionality.

Implementation of the task using the SKD Array and ConnectRows functions


The same steps, but with some additions, were used to create
.

Description of the JoinStrings function

JoinStrings

Used to concatenate strings into one string.

Syntax:

ConnectRows(Value, ItemSeparator, ColumnSeparator)

Options:

  1. Meaning— expressions that need to be combined into one line.
    If it is an Array, then the elements of the array will be combined into a string.
    If it is a ValueTable, then all columns and rows of the table will be combined into a row;
  2. Element Separator- a string containing the text to be used as
    separator between array elements and value table rows. Default – line feed character;
  3. Column Separators-a string containing the text to be used as a delimiter
    between the columns of the table of values. Default ";".

In light of the upcoming release of 8.2.14, I will try to describe some new functions of the data composition system.

Open the data layout diagram, preferably in an external report, to make editing easier.

We add a dataset of the query type and write, either manually or using the query designer, a simple query:

1. Set up a request in the access control system.

2. Set up calculated fields in the access control system

3. Configure the data layout on the settings tab

4. Launch 1C Enterprise 8.2.14. Open the report. We form, we receive.

Description of the new functions themselves:

1. The current date()

Returns the system date. When composing a layout layout, in all expressions that are present in the layout, the CurrentDate() function is replaced with the value of the current date.

2. COMPUTEEXPRESSION()

Syntax:

CalculateExpression(,)

Description:

The function is designed to evaluate an expression in the context of some grouping.

The function takes into account the selection of groupings, but does not take into account hierarchical selections.

The function cannot be applied to a grouping in the group selection of that grouping. For example, in selecting the Nomenclature grouping, you cannot use the expression CalculateExpression("Sum(SumTurnover)", "TotalTotal") > 1000. But such an expression can be used in hierarchical selection.

If the end record precedes the start record, then it is considered that there are no records for calculating detailed data and calculating aggregate functions.

When calculating interval expressions for a grand total (the Grouping parameter is set to GrandTotal), it is assumed that there are no records for calculating detailed data and calculating aggregate functions.

Layout linker when generating a function expression CalculateExpression, if the ordering expression contains fields that cannot be used in grouping, replaces the function CalculateExpression on NULL.

Options

Type: Line. The expression to be evaluated.

Type: Line. Contains the name of the grouping in the context of which the expression is to be evaluated. If an empty string is used as the grouping name, the calculation will be performed in the context of the current grouping. If the GeneralTotal string is used as the group name, the calculation will be performed in the context of the grand total. Otherwise, the calculation will be performed in the context of the parent group with the same name.

For example:

Sum(Sales.SumTurnover)/Calculate("Sum(Sales.SumTurnover)", "Total")

IN in this example the result will be the ratio of the sum by field Sales.AmountTurnover grouping records to the sum of the same field in the entire layout;

Type: Line. The parameter can take the following values:

· Grand total— the expression will be calculated for all grouping records.

· Hierarchy— the expression will be evaluated for the parent hierarchical record, if there is one, and for the entire grouping, if there is no parent hierarchical record.

· Grouping— the expression will be evaluated for the current group grouping record.

· GroupingNonResource— when calculating a function for a group record by resources, the expression will be calculated for the first group record of the original grouping.

When calculating a function CalculateExpression() with meaning GroupingNonResource for group records that are not grouped by resources, the function is calculated in the same way as it would be calculated if the parameter value was equal to the value Grouping.

The data composition layout builder, when generating a data composition layout when outputting the resource field by which grouping is performed to the layout, places an expression in the layout that is calculated using the function CalculateExpression() , indicating the parameter GroupingNonResource. For other resources, the usual resource expressions are placed in the resource grouping.

Type: Line. Indicates from which record the fragment should begin, in which aggregate expression functions should be calculated, and from which record to obtain field values ​​outside of aggregate functions. The value can be one of the following:

· First

· Last (Last)

· Previous

· Next (Next)

· Current

· LimitingValue(BoundaryValue) LimitingValue

Type: Line. Indicates to which record the fragment should be continued, in which the aggregate functions of the expression should be calculated. The value can be one of the following:

· First. It is necessary to obtain the first grouping record. After the word in brackets, you can specify an expression, the result of which will be used as an offset from the beginning of the grouping. The resulting value must be an integer greater than zero. For example, First(3) - receiving the third record from the beginning of the grouping.

If the first record is outside the grouping, then it is considered that there are no records. For example, if there are 3 records, and you want to get First(4), then it is considered that there are no records.

· Last (Last). You need to get the last grouping record. After the word in brackets, you can specify an expression, the result of which will be used as an offset from the end of the grouping. The resulting value must be an integer greater than zero. For example, Last(3) - receiving the third record from the end of the group.

If last record goes beyond the grouping, it is considered that there are no records. For example, if there are 3 records, and you want to get Last(4), then it is considered that there are no records.

· Previous. You need to get the previous grouping record. After the word in brackets, you can specify an expression, the result of which will be used as an offset back from the current grouping record. For example, Previous(2) - getting the previous from the previous record.

If the previous record goes beyond the grouping (for example, for the second grouping record you need to get Previous(3)), then the first grouping record is obtained.

When retrieving the previous record for a grouping total, it is considered that the first record is obtained.

· Next (Next). You need to get the next grouping record. After the word in brackets, you can specify an expression, the result of which will be used as an offset forward from the current grouping entry. For example, Next(2) - getting next from the next record.

If the next record goes beyond the grouping, then it is considered that there are no records. For example, if there are 3 entries and the third entry receives Next() , then it is considered that there are no entries.

When the next record is received for the grouping total, it is considered that there is no record.

· Current. You need to get the current record.

When retrieving for a grouping total, the first record is obtained.

· LimitingValue(BoundaryValue). The need to obtain a record by the specified value. After the word LimitingValue in brackets you need to indicate the expression with the value of which you want to start the fragment, the first ordering field.

The first record whose ordering field value is greater than or equal to the specified value will be returned as the record. For example, if the Period field is used as the ordering field, and it has the values ​​01/01/2010, 02/01/2010, 03/01/2010, and you want to get LimitingValue(DateTime(2010, 1, 15)), then a record with the date 02/01/2010 will be received.

Type: Line. Lists expressions, separated by commas, that describe the ordering rules. If not specified, then the ordering is performed in the same way as for the grouping for which the expression is evaluated. After each expression you can specify keyword Age(for ordering in ascending order), Descending(for ordering in descending order) and Auto-order(to order reference fields by the fields by which you want to order the referenced object). Word Auto-order can be used as with the word Age, so with the word Descending.

Type: Line. Same as parameter Sorting. Used to organize hierarchical records. If not specified, the layout builder generates the ordering according to the ordering specified in the parameter Sorting.

Type: Line. Specifies the rule for determining the previous or next record in case there are several records with the same ordering value:

· Separately indicates that a sequence of ordered records is used to determine the previous and next records. Default value.

· Together indicates that the previous and next records are determined based on the values ​​of the ordering expressions.

For example, if the resulting sequence is ordered by date:

date Full name Meaning
1 January 01, 2001

Ivanov M.

10
2 02 January 2001 Petrov S. 20
3 January 03, 2001 Sidorov R. 30
4 04 January 2001 Petrov S. 40

Separately, That:

§ the previous entry to entry 3 will be entry 2.

Current, Current(accordingly, parameters Start And End), then for record 2 this fragment will consist of one record 2. The expression will be equal to 20.

If the parameter value is Together, That:

§ the previous entry to entry 3 will be entry 1.

§ if the calculation fragment is defined as Current, Current(accordingly, parameters Start And End), then for record 2 this fragment will consist of records 2 and 3. Expression CalculateExpression("Sum(Value)", Current, Current) will be equal to 50.

When specifying a parameter value equal to Together, in parameters Start And End you cannot specify an offset for positions First, Last, Previous, Next.

CalculateExpression("Sum(SumTurnover)", "First", "Current")

If you want to get the grouping value in the previous line, you can use the following expression:

CalculateExpression("Rate", "Previous")

List new functions:

CalculateExpressionWithGroupArray(,) -

The function returns an array, each element of which contains the result of evaluating an expression for grouping by the specified field.

CalculateExpressionWithGroupValueTable(,) -

The function returns a table of values, each row of which contains the result of evaluating expressions for grouping by the specified field

ValueFilled() - Returns True if the value is different from the value of this type default, other than NULL, other than empty reference, other than Undefined. For boolean values the value is checked for NULL . Strings are checked for the absence of non-whitespace characters

Format(, ) - Receive a formatted string of the passed value. The format string is set according to format string systems "1C:Enterprise".

Substring(, , ) - This function is designed to extract a substring from a string.

Line Length() - The function is designed to determine the length of a string. Parameter is a string expression

Line() - If an array is passed as a parameter, the function returns a string containing string representations of all array elements, separated by "; " characters. If a table of values ​​is passed as a parameter, the function returns a string containing string representations of all rows of the table of values, with the cell representations of each row separated by ";" characters, and the rows by a newline character. If an element's string representation is empty, then a string is displayed instead of its representation.

In this short note I want to show how you can summarize values ​​at various levels of grouping in a report using a data composition system.
As shown in the image, only at the “Item Groups” grouping level, the “Order” resource is calculated, it displays how much needs to be ordered for the current item group based on certain conditions:


This value can only be calculated for this level groupings because, above or below, there are no values ​​to calculate. For example, at the level of detailed records, there is no data on the maximum quantity in a group, because this data is valid only for the group as a whole, and not for its individual components.

Accordingly, now it is necessary to calculate the totals for the above groupings (“Warehouses”, “Warehouse Types”) and the overall total.
To do this, use the function CalculateExpressionWithGroupArray:
EVALUATE EXPRESSIONWITHGROUPARRAY (EVALEXPRESSIONWITHGROUPARRAY)
Syntax:
EvaluateExpressionWithGroupArray(,)
Description:
The function returns an array, each element of which contains the result of evaluating an expression for grouping by the specified field.
The layout compositor, when generating a layout, converts function parameters into terms of data composition layout fields. For example, the Account field will be converted to DataSet.Account.
The layout builder, when generating expressions for the output of a custom field whose expression contains only the CalculateArrayWithGroupArray() function, generates the output expression so that the output information is ordered. For example, for a custom field with the expression:

CalculateExpressionWithGroupArray("Amount(AmountTurnover)", "Counterparty")
The layout builder will generate the following expression for output:

ConnectRows(Array(Order(CalculateExpressionWithGroupingValueTable("View(Sum(DataSet.AmountTurnover)),Sum(DataSet.AmountTurnover)",,"DataSet.Account"),"2")))

Options:

Type: String. The expression to be evaluated. String, for example, Amount(AmountTurnover).

Type: String. Grouping field expressions – expressions of grouping fields, separated by commas. For example, Contractor, Party.

Type: String. An expression describing the selection applied to detail records. The expression does not support the use of aggregate functions. For example,DeletionFlag = False.

Type: String. An expression describing the selection applied to group records. For example, Amount(AmountTurnover) > &Parameter1.
Example:

Maximum(CalculateExpressionWithGroupArray("Amount(AmountTurnover)", "Counterparty"));

A detailed description of the function syntax can be found at http://its.1c.ru/db/v837doc#bookmark:dev:TI000000582
Now for the calculation, let’s duplicate the “Order” field, with different “Calculate by...” values, using the following expressions, note that in each of the above standing level The values ​​of the levels below the groupings are used.

As a result, we get the following construction:

Proper use of a data composition scheme (DCS) allows you to:

  • significantly reduce the time required to develop a report;
  • get rid of the need to create controlled form processor;
  • get a beautiful result with the opportunity additional settings user.

But not all developers make the most of the scheme’s capabilities, since not all of its settings are obvious and intuitive. In particular, many people know that in 1C SKD there are calculated fields, however, they do not fully understand the scope of their use and methods of working with them.

What is a calculated field

In most cases, the data source in the layout diagram is a query. In principle, within the query itself you can already use various formulas, constructions and expressions. A natural question arises: why do we need duplicate functionality?

The fact is that the access control system is something more than just displaying the result of a query, and this is clearly visible from the diagram creation form (Fig. 1).

Calculated fields allow you to perform certain actions with the generated data set:

  • Output to specific cell an array of data obtained by a request, combining several lines into one;
  • Access export functions common module;
  • Execute the various expressions available for the layout language and use the special EvaluateExpression functions.

Let's go through this list.

Array of values ​​in one cell

Let's simulate a situation where it is necessary to receive all receipt document numbers for a counterparty in a separate cell:


Thus, we have created an additional calculation field in our scheme;


As you can see from the example above, there are no difficulties in adding and processing calculated fields. We used two functions: Array() and ConnectRows().

A few words about the latter. In addition to the first parameter indicating the identifier of the array, values ​​or value, two more can be set in it:

  1. Element Separator – indicates which character will separate one array element or one row of a table of values ​​from another (in our case, we omitted this parameter and a line break was assigned by default);
  2. Column Separator – a character used to separate columns of a table of values ​​(semicolon is used by default).

Accessing the export functions of a common module

Functions of a common module can act as a data source for filling a calculated field.

Some important points:

  • The function must be exportable;
  • If a function is located in a common module with the “Global” attribute set, it is called directly by name, otherwise the function must be called according to the “Shared module name” scheme. "Name of the function to be called."

As an example of use, we will take the same request for receipt documents and display it in a separate column. We will not describe the request itself; let’s move directly to the calculated fields:


Thus, we see that almost any data processor can be initialized from the access control system, which significantly expands the possibilities of using the scheme.

Layout language expressions

Quite often in a developer’s work a situation arises when it is necessary to display the result of division in the ACS field:

  1. Calculate the average cost of the item;
  2. All kinds of interest;
  3. Calculations of average earnings, etc.

To avoid problems, in these cases it is advisable to enter a test for division by 0 into the calculated field.

This can be done using the construction “Choice When….Then… Otherwise… End”.

Finally, a few words about enough new feature CalculateExpression(). With its help, in particular, you can calculate deviations in cost between the current and previous lines, cumulative balance, etc.

Let's say you can get the Document Amount from the previous line of our request by specifying the value Calculate Expression ("Document Amount", "Previous Amount") in the "Expression" field.

U this method It seems to me that there is a minus, but it works, but the minus is big. Let's look at an example: in the configuration there is a document "Receipt of goods" with tabular part“Products”, it is necessary to display in the report the documents and the names of the received goods for each document.

Let's create a report, add a basic data layout scheme, add a set of data of the "query" type to the access control system and generate a simple request (see Figure 1).

Figure 1. Data set query
On the “Calculated Fields” tab, add a calculated field called TabularPart and specify an empty string in the Expression column (see Figure 2).
Our calculated field will be used as a resource, so on the "Resources" tab we set the grouping expression: ConnectRows(Array(Products.Nomenclature),""). We also indicate that this resource must be calculated using the Link field (see Figure 3).
Result of the report:
The downside is the use of grouping; in our case, grouping is performed by the Link attribute, otherwise it will not work. The presence of a grouping imposes some restrictions on setting up data output (see Figure 4).

2) Calling your own function from a common module.

A simple and clear way, the only difficulty is to find a suitable common module or create a new one to write your own function :). Using the passed link to the document "Goods Receipt", the function will receive rows from the tabular part of the document and generate a row with information about the received goods. Let's start implementation.

Let's create a report, add a basic data layout scheme, add a set of data of the "query" type to the access control system and generate a simple request (see Figure 6).


Figure 6. Data set query
Let's create a common module _Demo Work WITH Reports and write the export function Get List of Products for Report(). See the function code below.
On the “Calculated Fields” tab, add a calculated field called TabularPart and in the Expression column we indicate a function call from the general module (see Figure 2):
_DemoWorking WITH Reports.Get List of Products for the Report (Link)

Let's go to the "Settings" tab and create a setting for data output - this will be a detailed record (see Figure 8).
Result of the report:

Download sample report

What you need to know when using this method:
1) The data composition engine expression may contain calls to functions of global common configuration modules. For example:
AbbreviatedName(Link, Date, Number)
2) When generating a report programmatically, the use of the functions of common modules is allowed only if the corresponding parameter of the data composition processor is specified (4th parameter):
CompositionProcessor = newDataCompositionProcessor;
LayoutProcessor.Initialize(LayoutLayout, DecryptionData, True);
3) Functions of common modules cannot be used in custom field expressions.
4) If an exception is thrown when generating a report indicating a function of a common module, check the module execution context (see Figure 9).

Description of the functions used

ConnectRows(Value, ItemSeparator, ColumnSeparator)- designed to combine strings into one line.
  • Value - expressions that need to be combined into one line. If it is an Array, then the elements of the array will be combined into a string. If it is a ValueTable, then all columns and rows of the table will be combined into a row;
  • Element Separator - A string containing text to be used as a separator between array elements and value table rows. Default – line feed character;
  • Column Separators - a string containing text to be used as a separator between columns of the value table. Default "; ".
Array([Various] Expression)- you can use a table of values ​​as a parameter. In this case, the result of the function will be an array containing the values ​​of the first column of the table of values, passed as a parameter. If the expression contains an Array function, then it is assumed that this expression is aggregate. If the Various keyword is specified, the resulting array will not contain duplicate values.

Get List of Products for Report (DocumentLink)- the function generates a line with a list of incoming goods.
// Options:
// DocumentLink - DocumentLink.Goods Receipt - Document "Goods Receipt".
// Return value:
// String - a string with a list of products.
Function Get List of Products for Report (DocumentLink) Export

List of Products = "";

For Each Line PM From DocumentLink.Products Cycle
List of Products = List of Products + Line TC.Nomenclature;
List of Products = List of Products + Symbols.PS;
EndCycle;

Return List of Products;

EndFunction // Get List of Products for Report()