— we began to discuss what 1C value types are and the conversion of 1C types.

Today we will talk in more detail about the types of 1C configuration objects (1C document type, 1C directory type, etc.)

Since in program code we work with values, we periodically need to know their type. Type 1C is always indicated in the metadata of the details - in directories and documents.

Working with 1C types is often used:

  • Conditions in the program
    Different actions depending on the type of 1C value in the “If ... Then ...” construction
  • Limitations when working in the interface
    Prohibiting or allowing the user to enter values ​​of certain types of 1C into a field on the form.
  • Determining the actual function/procedure parameter
    If a function/procedure parameter can be of any 1C type, then you need to define it in order to correctly obtain the value.

Type 1C can be obtained:

  • Determine the type of actual value 1C
  • Value objects have properties that indicate the allowed 1C type (for example, 1C types allowed in a table column, in a field on a form, in metadata) or methods that return these 1C types
  • From metadata - you can get the 1C type as it is specified in the metadata in the configurator.

Types 1C can be divided into three types:

  • Basic types 1C
  • Types of 1C databases (reference, objects)
  • Types 1C.

Definition of 1C type and comparison of 1C types

You can find out the type of value 1C using the function TypeValue (Variable)

To understand what 1C type this function returned, we need to specify the Type we need (“TypeName”)

For example, definition (comparison) of a type 1C variable:
If TypeValue(Variable) = Type("TypeName") Then

What types should I write as TypeName?

Basic types

Basic types of 1C - number, string, date, boolean.

For example:
Znch = 12;
If TypeValue(Value) = Type("Number") Then
ElseIf Value = Type("String") Then
ElseIf Value = Type("Date") Then
ElseIf Value = Type("Boolean") Then
endIf;

Database types

1C stores data in a database, but not in the form of individual records, but in the form of objects.

Most saved objects (including: directories, documents, enumerations, business processes, tasks) are available as an Object (for editing and writing) and as a Link (for reading). See "Links and Objects" for more details.

For example:
Value = Directories.Organizations.EmptyLink();
If TypeValue(Value) = Type("DirectoryLink.Organizations") Then
OtherwiseIf Value = Type("DirectoryObject.Organization") Then
OtherwiseIf TypeValue(Value) = Type("DocumentLink.Receipt of Goods") Then
OtherwiseIf Value = Type("DocumentObject.Receipt of Goods") Then
endIf;

Registers can be presented various types. The register type name is compound:
RegisterRegisterTypeAccessType.RegisterName

Types of 1C registers:

  • Information
  • Savings
  • Accounting
  • Calculation.

There are several types of register access. Most often used:

  • Set of Records
  • List
  • Sample
  • Record
  • RecordKey.

Total, example:
If TypeValue(Value) = Type("InformationRegisterList.RegisterName") Then
OtherwiseIf Value = Type("AccumulationRegisterRecordSet.RegisterName") Then
endIf;

The 1C language allows you to work with many objects created dynamically in the program, for example, an array, a list of values, a table of values, a structure...

Such 1C types are indicated by their name (in one word, without spaces). For example:
If TypeValue(Value) = Type("Array") Then
ElseIf Value = Type("List of Values") Then
endIf;

Determining the value of a 1C reference type

Work with all database objects (directories, documents...) is carried out through links. For example, if we want to make a reference in a document, then its 1C type will be “DirectoryLink.DirectoryName”.

For example:
Value = Directories.Organizations.EmptyLink();
If Directories.TypeAllLinks().Contains(TypeValue(Value)) Then
//this is a reference book
ElseIf Documents.TypeAllLinks().Contains(TypeValue(Value)) Then
//this is a document
endIf;

In a request, the 1C type can be checked in two ways.

The first is similar to that described, but the 1C type name does not indicate “Link” or “Object”, that is, instead of “DirectoryLink.Organizations” we write “Directory.Organizations”

For example:

Obtaining available 1C types

Many objects have a property.ValueType, which contains a list of 1C types:

  • Field on the fat client form
    Form Elements.FieldName.ValueType
  • Field on the thin client form (exception: called AvailableTypes)
    Elements.FieldName.AvailableTypes
  • Column of the table of values, tree of values
  • Form details
  • Selection element

How to work with this list of 1C types in the field.ValueType - see “Description of Types” in the “1C Language” section.

Working with types of 1C details in configuration metadata

When adding and editing details in the configurator, the programmer specifies the type(s) of 1C details. In the program code in the 1C language, you can get (find out) the type(s) of 1C details.

Basic methods:

  • For a 1C object, call the Metadata() method, which returns the metadata of a specific object and then work with the list of details (and details of the table section)
    Documents.Receipt of Goods.EmptyLink().Metadata().Details
  • Use the global variable “Metadata”, which returns all configuration metadata, and then access the details of a specific object
    Metadata.Documents.Receipt of Goods.Details

The attribute has a property.Type, which contains a list of 1C types set in the configurator for this attribute.

How to work with this list of 1C types - see “Description of Types” in the “1C Language” section.

Specify 1C type filter

For many objects it is possible to specify a filter of 1C value types that can be used, for example:

  • List of values ​​(.AvailableValues)
  • Managed Client Form Field (.AvailableTypes)

Where the filter is not available for modification, it is possible to specify the filter in the object method. For example, a column of a table (tree) of values ​​has.ValueType and we cannot change it, but when adding a column using the.Add() method, the second parameter can be used to specify a list of available 1C types.

To specify a list of 1C types for a filter, a list of 1C types is used; how to work with it, see “Description of types” in the “1C Language” section.

1C allows you to significantly simplify accounting or simply manage any organization, be it a small store or a large enterprise. The program is large system on database management. In order not to get confused in all this, you need to be able to perform various simple actions and understand the essence. Next, you will understand how to check the type of value in a request in 1C, as well as what they generally are, as well as how to distinguish between them.

Value types

1C: The enterprise has included a special function in new versions (platform 8.2). Using it, you can add any special parameters to any names or elements of the data system. This was done to make the system easier to edit and add new elements to. This function is called “Value Type”.

In fact, this is one of the basic concepts that most programming languages ​​contain. Using it, you can classify various data. For example: dates, numbers, strings, links. It's just basic classifications. There may be many more of them. Let's say, if you enter information about cities into your system, you can use: continent, country, region, etc.

Examination

You can check a particular field using a query language. Or rather its functions: TYPE VALUE. That is, if we want to find out what type of information the cell of interest contains, we must use the command.

VALUE TYPE(Value) = TYPE(String)

In the example above, we defined, using the command, simplest form. Another example of request validation:

Documentation

There are quite a few types; users can make do with the initial ones or enter their own to improve the information base. Here are some of them.

  • DocumentLink. It is applied for convenient storage references to various objects within other parts of the system.
  • DocumentObject - editing documents.
  • DocumentSelection - sorting through objects from the database.

In addition, there are special terms that characterize any data:

  • form;
  • line;
  • boolean;
  • number;
  • date of;
  • array;
  • checkbox;
  • picture.

These are just some of them. Any object can only be something from this list. Boolean is a special parameter that takes two values: true or false. There are also special tags that allow you to adjust the request: when, where, how, otherwise, etc. They set the program’s behavior algorithm. 1C is distinguished by the fact that these words here, like everything else, can be entered in Russian.

It is important to understand that all this will be perceived by beginners and non-professionals as Chinese literacy. To understand what we are talking about and effectively use 1C, you need to know the basics of programming. In general, checking the type in a request in the 1C program will be quite easy in comparison with other actions.

- classification of values ​​(that is, data) according to their type - strings, numbers, dates, etc. A value type is one of the basic concepts in any programming language.

Type conversion is the conversion of a value (data) from one type to another, such as from a string to a number or vice versa. A narrower concept of value formatting is conversion from any type to a string with conversion to a form that will be convenient for the user to read, including localization.

There are languages ​​with strong data typing. This means that when creating (defining) a variable, the programmer strictly specifies what type of data it can store. The same with functions, procedure parameters, etc. In 1C metadata, the type of details is strictly specified (although there is a composite type that allows you to specify several options). But in the program code in the 1C language there is no strict typing, which means that you can create a numeric variable, then equate it to a string. The function can, depending on the parameters and conditions, return a number, or a Boolean, or a string.

How to work with data types in the 1C language and how to convert 1C types?

Value 1C Undefined

Undefined is a 1C value that means there is no value. Using this 1C value, you can “zero” variables, including for implicitly calling a destructor, for example, COM objects.
Variable1 = New COMObject("Excel.Application");
Variable1 = Undefined;

A similar value is 1C NULL, which can be returned by a request when trying to obtain data from the database, if it was not possible to obtain it (more precisely, the value in the NULL field means that the field in the database is “not filled”).
Select = Query.Run().Select();
While Select.Next() Loop
If Selection.Field1 = NULL Then
Continue;
endIf;
EndCycle;

Types of 1C values

It is possible to use the following as “variables”:

  • Variables created in the program text (using the methods described above)
  • Details of the metadata object or form (created in the configurator, indicating the exact 1C type).

The props can have a composite type 1C, that is, several possible ones. Assigning the 1C value by the user in this case can be a two-step process:

  • Selecting a 1C value type from the available ones
  • Selecting the value 1C.

By default, this attribute has the value 1C Undefined. When the 1C type is selected, but the 1C value has not yet been selected, the empty value of this 1C type (0 for a number, an empty link for 1C reference types, see below). And finally then – the value 1C. From the program, values ​​are assigned directly, without intermediate selection of the 1C type.

It is possible to determine the type of 1C value in several ways:
//method 1 – comparison with known 1C types
Variable1 = 12;
If TypeValue(Variable1) = Type("Number") Then
//…
OtherwiseIf TypeValue(Variable1) = Type("DirectoryLink.DirectoryName") Then
//…
endIf;

Conversion of 1C types

Meaning 1C simple types 1C can be converted using the operator - 1C type name:
//to number
ValueNumber = Number("22"); //if it is impossible to convert 1C types, an error will be raised, so it is better to use an error handler (see below)

//to the line
ValueString = String(22);
ValueString = AbbrLP(22);
ValueString = Format(22, "CHG=0");

//on date
ValueDate = Date("20120101120000"); //01.01.2012 12:00:00
ValueDate = Date(2012, 01, 01, 12, 0, 0);
ValueDate = Date(2012, 01, 01);

Conversion of 1C types - values ​​of complex 1C types

Formatting 1C values

To specify the exact format, the Format() function is used, with which it is possible to specify the required representation.
NumberString = Format(2400, "Settings")

In the “Settings” line you need to specify the required 1C format. Such settings are indicated in a special encoded form. Let's look at the most commonly used settings:

1C format of dates and numbers according to the rules of various countries
If you need to display a date or number and don’t want to bother with knowing how they should be presented according to the rules of the desired country, there is a simple setting that will allow you to do this:
L = Short Name of the Desired Country

An example of date output according to the rules of some countries:
Format(CurrentDate(), “L=ru”)
> 28.03.2012 14:21:32
Format(CurrentDate(), "L=en")
> 3/28/2012 2:21:24 PM
Format(CurrentDate(), "L=fr")
> 28/03/2012 14:22:08

Date format in 1C language
If the default setting is not enough for you and you would like to independently specify the order of the date parts and the symbols for separating them, you must use the setting:
DF = "dmg chms"

Accordingly, “dmg” is the day, month and year, and “chms” is the hours, minutes and seconds. It is possible to skip any of these parts. The order is any. The characters specified between the parts will be used as separation characters.

Date part symbol m.b. is indicated several times in a row, the type of this part of the date depends on this, for example “d” or “dd” or “dddd”.

Explanation of date parts:

  • d – day
    o small "d"
    o from 1 to 4 times
  • M – month
    o big "M"
    o from 1 to 4 times
  • g – year
    o small "g"
    o 1 or 2 or 4 times
  • h – hours
    o small “h” - 12 hour format
    o large “H” - 24-hour format
    o 1 or 2 times
  • m – minutes
    o small "m"
    o 1 or 2 times
  • s – seconds
    o small "s"
    o 1 or 2 times
  • bb – display AM/PM for 12-hour format
  • k – quarter.

An example of displaying a date indicating the rules:

Number format in 1C language
Unlike formatting a date, where everything is quite simple, formatting a number has many options. Here are those that are most often used.

The first "problem" is related to the default grouping of digits in numbers by 3 and separating the groups with a space, for example:
StrNumber = String(22300500)
> 22 300 500

This is inconvenient when a number is converted to a string not for beautiful and understandable output to the user, but for service needs. This can be influenced using the “CHG” parameter, for example:

A parameter that allows you to round a number when outputting to the required number of digits after the decimal point “NFR”:
Format(3.535353, "BDT=""2""")
> 3,54

A parameter that allows you to specify the separator character for the integer and fractional parts of “BRD”:
Format(3.535353, "BRD="".""")
> 3.535353

In some cases, it can be useful to be able to display something else instead of the number “0”: an empty string or “not filled”. This allows you to do the “CHN” parameter:
Format(0, "CHN=""""")

There are a lot of predefined value types in 1C; they can be divided into several groups.

Fast passage

Data type groups

  • simple (primitive) types
  • object types and their subordinates
  • object types from metadata (application types)
  • interface types
  • other general purpose types

Simple types

  • String (specified by the value in quotes "")
  • Number (Specified as a decimal number)
  • Date (date and time)
  • Boolean (True, False.

Object types

  • Collections of values ​​(Arrays, Structures, Value Tables and others)
  • Integration (Com, files, external objects, zip, WS)
  • General purpose

Objects from metadata (application)

  • Constants
  • Directories
  • Documentation
  • Transfers
  • Reports
  • Treatments
  • Charts of accounts
  • Tasks
  • Information registers
  • Savings registers
  • Accounting registers
  • and others…

Interface

Related to windows, forms and form elements (fields, labels, tabular data and others)

Other options for subdividing values

  • Values ​​that can be written down to the object details (in the field information base) and those which are not allowed
  • Objects that can be visualized, and those that have virtual entity
  • Value types that, related to the configuration and its objects or working separately
  • Which can be differentiated according to user rights - cannot
  • They can quite simple transform- either auxiliary conversion required
  • Eat properties and methods- either none

Setting Value Types

The value can be set:

Directly

This_Variable = "This is a string value";

Through object creation

This_Variable = NewColor;

Through the result of a system function call

This_Variable = Date(2016,1,1);

By accessing an object property

This_Variable_Object_Color = New Color; This_Variable = This_Variable_Object_Color.Green;

Compound and simple types

Unless specifically stated, the value type is not limited.

In the case of details of metadata objects, the type of values ​​is set at the configuration stage from the types available for writing (primitive, links to objects, value storage), as well as from the type of object and context (environment, place) of execution. In this case, it is possible to limit the props to one type or several. For example, we need to write either a “string” value or a “number” value in one field.

For other objects, the type of details may remain unrestricted (of an arbitrary type), or limited through a special type " DescriptionTypes«

For example, for the simple case

Type Description = New Type Description ("Number, String");

This object is also used to limit the selection or entry of data in dialog forms

Casting values

Produced automatically when assigning an object to an attribute (property), if this attribute cannot store this value

Also, during concatenation operations, it is carried out first to the first term, when subtracting, if possible, to the second, and then to the result.

Color = New Color(255,0,0); Color2 = New Color("2"+59-Color.Red,0,0); //In this case, it will happen in stages //"2"+59 ="259" //259-255 = 4 //Color2 = New Color(4,0,0);

Such “complex” conversions must be carried out with caution.

Casting values ​​using built-in conversion functions

ThisWillBeNumber = Number("15"); ThisWillAString = String(ThisWillANumber); ThisWillString = Format(ThisWillNumber,"");//it is possible to specify a formatting string for the value ThisWillDate = Date("201601+ThisWillANumber);//time will be 00:00:00 //Casting through an object CanOnlyBeNumber = New TypeDescription("Number") ; ThisWillBeNumber = CanOnlyBeNumber.GiveValue("12");

Please note that the system will not be able to make some transformations, and this will cause a runtime error, so the check must be carried out by the developer

ThisAssignmentWillNotHappen = Date("12:45:45");

Type checking

The comparison is made through the special functions TypeValue() and Type().

The first returns the value of the passed type, the second sets the type to be checked

ThisNumber = 15; //answer to the question: is the value type of the variable "ThisNumber" of type "Number" ThisBoolean = TypeValue(ThisNumber) = Type("Number"); //The first sign "=" is an assignment //The second "=" is a comparison for equality

The “Type” object itself is auxiliary and cannot be written to details

Comparison of values

Produced:

  • when comparing for equality based on a clear match between type and value, no casting is performed
  • comparison by > or< (на больше-меньше) допустимы только для значений совпадающих примитивных типов (Булево, Число, Строка, Дата)

I won’t go into more detail about the types; it’s better to get a feel for them in real problems or narrow examples

Attention! This is an introductory version of the lesson, the materials of which may be incomplete.

Login to the site as a student

Log in as a student to access school materials

Query language 1C 8.3 for beginner programmers: functions and operators for working with types (VALUE TYPE, TYPE, REFERENCE, ISNULL, EXPRESS)

Let's remember that each attribute (property, field) of a directory, document or any other application object has its own type. And we can look at this type in the configurator:

In the query language, there is a whole class of functions and operators for working with types of details. Let's look at them.

VALUE TYPE function

This function takes one parameter (value) and returns its type. For the props described in the picture (above) Taste directory Food the following will be returned:

Now let's look at the props Distinctive Feature at the directory Cities:

You see that this prop can be one of several types: Line, Directory.Tastes, Directory.Colors. This type of details is called COMPOSITE.

If we try to fill in the value of such a detail in 1C:Enterprise mode, the system will ask us what type of value will be entered:

And only after our selection will it allow us to enter the value of the selected type.

Thus, directory elements of the same type ( Directory.Cities) will be able to store in the same attribute ( Distinctive Feature) values different types(String, Colors or Flavors).

You can see this for yourself by clicking on the elements of the directory Cities in 1C:Enterprise mode. You are reading a trial version of the lesson, full lessons are available.

Here the distinguishing feature value is a directory element Flavors:

Here's the line:

And here is generally an element of the reference book Colors:

These are the possibilities a composite data type opens up for us!

I wonder how the function will behave TYPE VALUES on the props DistinctiveElement, having a composite data type:

This is already very interesting. Let's look at each line individually.

The type of value of the distinctive feature for the element Russia is equal to NULL. This is the first time we have encountered this type. Values of this type are used solely to determine the missing value when working with the database.

So it is, because the element Russia is a group, and not ordinary element directory Cities, so it has no field Distinctive Feature. And the type of a missing value, as we read above, is always equal to NULL.

The type of value of the distinctive feature for Perm is equal to Flavors. This is true, because the value of the distinctive feature entered in the database for the city of Perm is a link to the directory element Flavors.

For Krasnoyarsk, the type of attribute is equal to Colors, because the value selected in the database is a link to a directory element Colors.

For Voronezh, the type of attribute is equal to Line, because the value entered in the database is a regular string.

India is a group again, so there is no significance. And the type of the missing value, as we remember, is equal to NULL.

Here's the thing. If you go to the directory element Cities with name Sao Paulo, then you will see that the field Distinctive Feature not filled in at all. It's empty. A all empty fields of a composite type have a special meaning UNDEFINED .

WITH UNDEFINED we are also encountering for the first time. Meaning UNDEFINED used when it is necessary to use an empty value that does not belong to any other type. This is exactly our situation. And the value type UNDEFINED, as you probably already guessed, is equal to NULL.

Function TYPE

It takes only one parameter - the name of the primitive type ( LINE, NUMBER, DATE, BOOLEAN), or the name of the table whose link type you want to get.

The result of this construct will be a value of type Type for the specified type.

Sounds vague, doesn't it?

Let's look at the application of this design and everything will immediately fall into place.

Suppose we need to select all directory entries Cities, which have composite props Distinctive Feature has a value of type LINE:

Now let's select all records that have attribute values Distinctive Feature are links to directory elements Colors(table Directory.Colors):

Retreat

As you remember, some elements of the directory Cities don't have props Distinctive Feature. Function TYPE VALUES for such elements it produces NULL.

How can you select such elements in a query? A special logical operator is provided for this IS NULL(not to be confused with the function ISNULL, which we will look at below). You are reading a trial version of the lesson, full lessons are available.

Here is an example of its use:

Great. But did you notice that there is no element of Sao Paulo, props value type Distinctive Feature which he also gave out NULL. Why did it happen?

But the thing is that the situation for groups (Russia, India, Brazil), for which filling out the details Distinctive Feature impossible in principle, since they don’t have it at all, differs from the situation for the Sao Paulo element, for which filling in the props is possible, but it is simply not filled in and is equal, as we remember, to a special value UNDEFINED.

To select all records that have the requisite Distinctive Feature present, but not filled, a different construction should be used:

But comparison with UNDEFINED to determine empty (unfilled) attributes will only work for composite types.

By the way, logical operator THE IS NULL form of negation looks like this:

Logical operator LINK

For example, let's select from the directory Cities only those records that have the value of a composite attribute Distinctive Feature are a link to a directory element Flavors:

As you remember, we could solve the same problem using TYPE VALUES And TYPE:

Function ISNULL

The function is designed to replace a value NULL to a different meaning.

We remember that the meaning NULL returned if the requested attribute (field, property) does not exist.

For example, props Distinctive Feature for directory groups Cities:

Function ISNULL will help us output a different value if this value is equal to NULL. You are reading a trial version of the lesson, full lessons are available. Let in this case be the line “There is no such prop!”:

It turns out that if the first parameter of the function ISNULL not equal NULL, then he returns. If it is NULL, then the second parameter is returned.

EXPRESS function

This function is only for fields that have a composite type. An excellent example of such a field is the property Distinctive Feature for directory elements Cities.

As we remember, composite fields can be one of several types specified in the configurator.

For field Distinctive Feature such valid types are LINE, Directory.Colors And Directory.Tastes.

Sometimes it becomes necessary to cast the values ​​of a composite field to a specific type.

Let's list all field values Distinctive Feature to type Reference.Colors:

As a result, all element values ​​that were of type Directory.Colors, remained filled and were converted to the specified type. All values ​​of other types ( LINE, Directory.Tastes) are now equal NULL. This is the peculiarity of type casting using the function EXPRESS.

You can cast a type either to a primitive type ( BOOLEAN, NUMBER, LINE, DATE) or to a reference type. You are reading a trial version of the lesson, full lessons are available. But the type to which the cast is being made must be included in the list of types for this composite field, otherwise the system will throw an error.

Take the test

Start test

1. Choose the most correct statement

2. Details that can take values ​​of one of several types are called

3. To determine the type of attribute value, use the function

4. Empty details of a composite type are important