How to check the value type of a document or directory? 1c how to determine the type of a value.

1C allows you to significantly simplify accounting or simply manage any organization, be it a small store or a large enterprise. The program is a large database management system. 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. These are 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 the simplest type using the command. 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 used for conveniently storing 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.

— 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 changing 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 of various types. Composite register type name:
RegisterRegisterTypeAccessType.RegisterName

Types of 1C registers:

  • Information
  • Savings
  • Accounting
  • Calculation.

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

  • SetRecords
  • 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;

Defining 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.

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 ​​of 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.

This is true, because the Russia element is a group, and not an ordinary directory element 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 absolutely 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 whom he also gave out NULL. Why did it happen?

But the thing is that the situation is 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, the logical operator IS NULL has a negation form that 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 there is a need 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 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

Defined types are a new 1C metadata object that appeared in platform version 8.3. The object is of an auxiliary nature. Let's consider what the defined types are and the tasks that this object can solve.

Defined are new data types, the set of which is determined by the developer of the application solution. It consists of several valid types. This data type can be the type of any configuration attribute, except for the defined type itself and the “ “ object.

Get 267 video lessons on 1C for free:

Settings

There are not so many settings for this object:

Those. in addition to the name and synonym in 1C, defined types have only a set of object types.

An example of using defined types in 1C 8.3

A great variety of applications can be found for this object.

Examples of using:

  • you can describe in the configuration details that refer to data that will be defined when the fragment is embedded in a specific configuration;
  • assign one type of defined data to a certain set of event subscriptions; when the set of types changes, the source will change dynamically for all subscriptions;
  • use as an alternative to the plan of characteristics types

and much more.

If you are starting to learn 1C programming, we recommend our free course (don’t forget