Add a line to the tabular part of document 1s 8.3. Hotkeys: general actions

For the previous example, you can add the following lines of code:

Form Elements.TableField1.AddRow(); page = FormElements.TableField1.CurrentRow; p.First = 3; p.Second = "Flour"; p.Quantity = 350;

How to determine the number of rows in a table of values ​​in 1s 8?

countRows = table.Quantity(); Report("Number of rows in table of table values ​​= " + number of rows);

Result:

Number of rows in table of table values ​​= 3

How to delete a row in a table of values ​​in 1s 8?

rowTable = table; table.Delete(rowTable);

How to collapse a table of values ​​in 1s 8?

Collapse:

table.Collapse("Second", "Quantity");

We get after convolution:

How to sort a table of values ​​in 1s 8?

Sort by the second and third columns:

table.Sort("Second, Quantity");

How to position a table field on a line in 1c 8?

On the second line:

Form Elements.TableField1.CurrentRow = table;

Printable form in 1s 8

First, we make a layout (name of the area: select the required lines of the layout, in the properties, in the Name field, enter the name of the area), then display it in a spreadsheet document:

Procedure CommandPanel1Print(Button) variable td, rs, rs1, layout, code, name, nomen; code = 0; layout = GetLayout("Products"); header = layout.GetArea("Header"); header.Parameters.datta = CurrentDate(); pc = layout.GetArea("pc"); pc1 = layout.GetArea("pc1"); td = New TabularDocument; td.Output(cap); nomen = Directories.Nomenclature; selection = nom.SelectHierarchically(); while fetch.Next() loop code = code + 1; if sample.ThisGroup = True then pc1.Parameters.code = code; pc1.Parameters.name = selection.Name; td.Output(rs1); else rs.Parameters.code = code; rs.Parameters.name = selection.Name; td.Withdraw(rs); endIf; endCycle; etc.ViewOnly = True; td.Show("Directory ""Nomenclature"""); EndProcedure

The basic capabilities of a programming language usually include working with numbers and strings. Usually these features are hard-coded into the compiler code (or the “base” classes of the programming language are implemented).

In 1C, the ability to work with strings is programmed in the platform itself. Today we will look at the features of working with 1C strings in programs in the built-in 1C language.

Line value 1C

1. Let's start with the simplest. Creating a variable and assigning a constant string value to it looks like this in 1C:

Variable = "Hello, world!";

If you need to specify a quote character in a constant 1C string value, then you need to double it “”

Variable = "Hello, world"!;

2. Line break 1C can be specified in two ways at once. The first is using the symbol |

Variable = "Hello,
| world! ";

The second is using the Symbols system enumeration. It allows you to add both 1C line breaks and other non-printing characters, such as TAB.

Variable = "Hello" + Symbols.PS + "peace!";

3. Configurations in 1C can be developed not only for one language (Russian, English or another) - but simultaneously for several languages. In this case, the currently used language is selected at the bottom of the 1C window.

The list of languages ​​is located in the configuration window in the General/Languages ​​branch. Each language has a short identifier such as ru or eng.

It is clear that when programming such a configuration, 1C lines can also be multilingual. To do this, it is possible to create such a 1C line by specifying through; options by language identifier:

Variable = "ru=""Hello, world! ""; en=""Hello, world! """;

If you use the 1C line formed this way as usual, then it will be what is written in it. In order for the system to split it into two options and use the desired one, you need to use the НStr() function:

//correct for bilingual configurations
Report(NStr(Variable));

Props with line type 1C

The attribute is a field in the 1C directory/document. It differs from a variable in a program in the 1C language in that for the attribute its type is precisely indicated (number, 1C string, etc.). If you need to refresh your memory of what a prop is, watch the lesson on.

If you specify the type of attribute - line 1C, then you must additionally specify the parameters.

1C lines come in unlimited length (indicated as length = 0) and limited length, indicating the exact number of characters. 1C rows of unlimited length are stored in a separate SQL table, so their use is less productive than limited ones.

That is why the use of 1C strings of unlimited length has its limitations - it is not possible to use them everywhere. For example, it is not allowed as a document number, reference code, or measurement.

Working with 1C strings

There are several built-in functions of the 1C platform for working with strings.

  • AbbrLP (“Incredible, but true!”)
    Removes extra spaces from the 1C line. Can also be used to convert any types to a 1C string (for example, numbers).
  • Variable = "Vasya" + AbbrLP(" plus") + "Olya"; //there will be "Vasya plus Olya"
    An example of summing several 1C string values. The result will be one line 1C.
  • Variable = Lev("Music", 2); //will be "Mu"
    Variable = Medium("Music", 2, 2); //there will be "threat"
    Variable = Rights("Music", 2); //there will be "ka"
    Various options for obtaining a substring from a 1C string.
  • Variable = Find("Music", "zy"); //there will be 3
    Search for a substring in string 1C, starting with character 1.
  • Variable = StrLength("Music"); //there will be 6
    Returns the number of characters in the 1C line.
  • Report("Hello") //in the message window at the bottom of the 1C window
    Alert("Hello") //popup dialog
    Status("Hello") //in the status display line at the bottom left
    .

Bringing objects to line 1C

As you know, the most popular format for exchanging structured information at present is XML. Even the latest version of MS Office Word and Excel save files in this format (docx and xlsx, respectively, change the extension to zip, open in an archiver).

The 1C platform for data exchange provides several options, the main one of which is also XML.

1. The simplest method is to use the Abbreviation() or String() function. You can use the REPRESENTATION() function in the request body. The result of their action is the same - they generate a string representation of any 1C object for the user.

For a directory by default, this will be its name. For a document – ​​document name, number and date.

2. Any 1C object (with restrictions) can be converted to XML and vice versa. The conversion process is called serialization.

StringViewXml = XMLString(Value); //get XML from 1C value
Value1C = XMLValue(Type("DirectoryLink.Nomenclature"),TypeStringXml); //get the 1C value from the XML string, you must specify the 1C type that should be received

3. There is the 1C platform’s own way to convert any 1C object into a string. It migrated from version 1C 7.7. This format is not understood by other programs, but other 1C understands it, which makes it easy to use it for exchange between 1C databases.

Row = ValueInRowInt(Value1C); //get string 1C from value 1C
ValueVFile("C:\MyFile.txt", Value1C); //another option, we get a file with a saved string from the 1C value
Value1C = ValueFromStringInt(String); //back from line 1C
Value1C = ValueFile("C:\MyFile.txt"); //back from file

Editing 1C lines on the form

In addition to working with 1C strings in a program in the 1C language, of course I would like the user to be able to edit them. There are several possibilities for this:

1. The easiest way is to request the entry of a 1C line on demand. This method is used when teaching 1C programming; in life it is used much less often (but it is used!).

Variable = "";
Row = EnterValue(Variable, "Enter Full Name");

2. To display the details of a 1C object (directory/document) or form details (see), an input field is most often used. This is the most common tool in 1C for the user to work with editing fields.

3. The capabilities of the input field can be expanded (see properties of the input field, right-click on it, more details):

  • Checkbox Multiline editing mode
  • Advanced editing checkbox (available if the previous checkbox is checked)
  • Checkbox Password mode (see).

4. If all the capabilities of the input field are not enough for you, there is a built-in editor. To add it to the form, you need to add a Text Document Field to the Form/Insert Control menu. In its properties you can specify its operating mode – the Extension property.

A text document field cannot be associated directly with data. It is necessary to write a function in the OnOpen() event handler of the form (see):

Form Elements.ElementNameTextDocumentField.SetText(StringValue); //here ValueString is the text received, for example, from the attribute

And in the save handler - for example, in the Save button - add a save:

ValueString = FormElements.ElementNameTextDocumentField.GetText(); //ValueThe line here is the attribute where we save the value

5. In 1C version 8.2.11, in managed forms, a new option has appeared for representing a 1C line - the Formatted Document field.


Similar to the field of a text document, you must set it when opening it and write it down when saving it yourself using the program.

  • In the 1C object whose form we are creating (directory, document, processing, etc.) - add an attribute with the Value Storage type
  • In the OnReadOnServer() function we set the text from the attribute

    //here the Attribute is the added attribute of the 1C object
    //here FormattedDocument is the name of the field on the form for editing
    &On server

    FormattedDocument = CurrentObject.Attributes.Get();
    EndProcedure

  • In the BeforeWritingOnServer() function or using the button, we will write the text from the field

    &On server
    Procedure When ReadingOnServer(CurrentObject)
    CurrentObject.Props = NewValueStorage(FormattedDocument);
    EndProcedure

Tabular parts exist for many objects in 1C:

  • Directories
  • Documentation
  • Reports and processing
  • Charts of accounts
  • Characteristic type plans
  • Calculation type plans
  • Business processes and tasks

Tabular parts allow you to store an unlimited amount of structured information belonging to one object.

Let's look at some techniques for working with tabular parts.

How to bypass the tabular part

To traverse the table part, you can use a loop For each

For each Row from the Tabular Part of the Cycle

Report(String. TabularPart attribute) ;

EndCycle ;

At each iteration into the variable Line the next row of the tabular section is transmitted. The values ​​of the row details can be obtained by the expression Line.AttributeName.

How to get and bypass selected rows of the tabular part

To display information from the tabular part of the object, use a form element Table field. To enable the ability to select multiple rows in a table field, you need to set the value Multiple at his property Selection mode.

To get a list of selected lines, use the following code:

A loop is used to iterate through the selected lines. For each:

SelectedRows = FormElements. TableFieldName. SelectedRows;

For each Row from Selected Rows Loop

//loop contents

EndCycle ;

How to programmatically select rows of a tabular part (table field) and deselect them

To programmatically deselect rows of a table field:

Form Elements. TableFieldName. SelectedRows. Clear() ;

To programmatically select all rows of a table field:

For each CurrentRow From TabularPart Loop
Form Elements. TableFieldName. SelectedLines. Add(CurrentRow) ;
EndCycle ;

How to clear the table part

TabularPart. Clear() ;

How to get the current row of a table section

The current line is the timeline in which the user currently has the cursor. To get it, you need to access the control element on the form that is associated with the tabular part.

For regular forms the code will look like this:

Form Elements. TableFieldName. CurrentData;

For managed forms:

Elements. TableFieldName. CurrentData;

How to add a new row to a table section

Adding a new line to the end of the table part:

NewRow = TablePart. Add() ;

Adding a new line anywhere in the table section (subsequent lines will be shifted):

NewRow = TablePart. Insert(Index)
//Index - number of the added line. Line numbering starts from zero.

New line. Props1 = "Value" ;

How to programmatically fill in the details of a table row

If you need to programmatically fill in the details of a table section row that is added by the user, you must use the table section event handler When StartingEditing.

The procedure created by the handler has three parameters:

  • Element- contains a control element TabularField.
  • New line- boolean. Contains value True, if a new table row is added, and Lie, if the user started editing an already existing line.
  • Copy- boolean. Contains value True, if the user copies the line, and Lie in other cases.

Let's look at an example. Let's say we need to fill in the details of the tabular section AccountAccount, in case a new line is added. When editing an existing line, you do not need to change the accounting account.

Procedure TabularPartAtStartEditing(Element, NewRow, Copy)

//If the user edits an existing line, then we do nothing
If NOT NewRow Then
Return;
EndIf ;

//If the line is new, set the accounting account
TechString = Item. CurrentData; //Get the current row of the tabular part
TechString. Accounting = Charts of Accounts. Self-supporting. RequiredAccount;
EndProcedure