How to set up smartphones and PCs. Informational portal

Data types in 1c enterprise. Using Defined Types

Data types in 1C: Enterprise 8.x

Before diving into embedded language constructs, we need to become familiar with the basic data types. Fortunately,:

Beginners to learn the 1C platform sometimes get confused about the definition of data types and any linguistic nuances that arise. This first article is introductory and is devoted to primitive data types 1C, there are not so many of them.

Number. Numbers in 1C mean both integer and floating point values. The maximum word length for a value of the "number" type can be 32 characters, including the decimal point. It should also be borne in mind that the 32-character limit applies to numbers that will be written to the database. It is possible to declare a variable and assign a value greater than 32 characters to it. For numeric values ​​that are stored in memory, this limitation does not apply. After declaring a variable of type "Number", its value will be 0.

Line. As in any other programming language, 1C implements all the necessary functions for manipulating strings. Values ​​of this type are represented in Unicode. The length of variables of type string is not limited.

Date. In addition to the date itself, values ​​of this type also contain time. Time refers to hours, minutes and seconds. Immediately after the initialization of a variable of the "Date" type, it will be assigned the value (date) "01 January 0001 00 hours 00 minutes 00 seconds". This is sometimes annoying, but over time you get used to it.

Boolean. This is understandable that variables of this type can take only two values: True, False.

Undefined. Values ​​of type "undefined" are used when you need to specify an empty value that does not belong to any other data type. For example, you need to declare a variable that will then be used somewhere. You can assign it a value like 0 or "" (that is, an empty string), but by doing so we immediately set the appropriate type for it (number or string). But what if the installation of one of these types later can interfere? In such cases, you can use a value of the "undefined" type. It is also worth noting that many functions of the embedded language, in case of unsuccessful execution, return a value of this type as a result. When describing its functions, it is recommended to follow the same rule.

Null. The general meaning of Null is almost the same as that of "undefined." Values ​​of this type are used to indicate a missing value in the database. Most often, you can get values ​​of this type using the query language. For example, a query that uses table concatenation. Suppose one of the tables does not contain a value that satisfies the condition. In this case, the missing value will be replaced by a Null value.

It is possible to encounter a value of type Null not only when working with queries. For example, a Null value accepts attributes that are not used by the object. Let's imagine that we have a hierarchical directory with the "quantity" attribute. When creating this attribute, the "Usage" property was set to the value "For the element". If you try to refer to this attribute for a dictionary element of the "group" type, then its value will just be Null.

Type of. This type is used to determine the available types. Sounds a little confusing? Ok, I'll try to explain it with an example. Imagine that you are faced with the task of comparing the types of two variables. In code, it will look something like this:

Variable1 = 123; // Since we assigned a number, the type of the variable will be "number".
Variable2 = "string"; // Here we assigned a string, so the type of the variable will be string.

Now you need to make sure 100% that variable1 is numeric. This is where the Type "type" comes in handy (sounds funny), as well as a couple of auxiliary functions. Will not go into details yet. Just take a look and try to understand the example below:

If (TypeZnch (Variable1) = Type ("Number")) Then

Report ("Variable1 is numeric!");

Otherwise

Report ("Variable1 is NOT numeric :(");

EndIf;

In this small piece of code, I first get the type of the variable using the "TypeVal ()" function. This function takes as a parameter the value of the type you want to get. In our case, this is "Variable1". Then I need to get a value of type "Type" that characterizes the type "Number". For this, the built-in language provides the "Type ()" function. It takes only one argument, the string representation of the type name. Since we need to compare with the "Number" type, the parameter for the function will be "Number".

Thank you for help in writing this article by Igor Antonov.

Type system is a special system by which the data used by application solutions is organized. The type system allows you to represent information in the real world in terms "understandable" for 1C: Enterprise 8.

The type system provides ample opportunities both for describing directly the business logic of applied solutions and for performing intermediate data processing tasks.

The type system is described in the syntax helper, online help, and documentation.

The main feature of the type system is that there are types that exist in any application solution. These types themselves are defined at the platform level and are always present, regardless of the developer's actions. Along with them, in a specific application solution, there may be various types of data inherent in this specific application solution. For such data types at the platform level, only general rules for their creation, templates, are defined. And concrete data types are created by the platform based on how the developer forms and modifies the structure of the applied solution.

Data types defined at the platform level

The set of types that application solutions can operate on is quite diverse. It allows solving both data processing tasks and the tasks of presenting this data to the user and interactively working with them. There are several main categories of data types.

Primitive types

Primitive data types are types such as Line, Number, date, Boolean other. These types are not something special for 1C: Enterprise 8. As a rule, such data types also exist in other software systems.

Values ​​of primitive types are simple, indivisible values ​​that cannot be distinguished from their individual components. For example, values ​​like Number can be 1, 8, 15, etc. To create a value of a primitive type, you need to specify it in the program text literal- symbolic identifier of the value.

Generic collections of values

Also, there are more complex data types. For example, the platform supports a number of types that are generic collections of values: Array, Structure, List of Values other.

Common types

In addition, the platform implements specific data types that implement one or another functionality of applied solutions: Text Document, TabularDocument, StorageValues, Query Builder other.

Common types are also called common facilities... The values ​​of these types, in contrast to the values ​​of primitive types, are a collection of values ​​of individual properties of an object. Therefore they are called object instances.

Object instances are created using the special embedded language operator - New.

Interface types

Interface types allow organizing the visual interaction of the applied solution with the user. Basically, these are types related to the operation of forms and their elements.

Data types generated in the application solution

However, in addition to the data types that are defined at the platform level, a specific application solution can use unique data types that exist only in this specific application solution. Moreover, the platform will fully support working with these data types in the same way as with the types that are defined at the level of the platform itself.

As a rule, the appearance of new data types in an application solution is associated with the use of application configuration objects. Therefore, these types are also called applied types or applied objects.

At the platform level, several classes (templates) of application objects are supported, which by themselves cannot be used in a specific application solution. For example, you can enumerate classes of application objects such as Directories, The documents, Information registers, Charts of characteristic types etc.

For each class of applied objects, the corresponding basic functionality is defined: types of database tables that must be created to store data, standard forms, standard language objects, sets of rights, etc.

A developer, creating an application solution, is not able to use these classes directly, however, he can add a new configuration object to his application solution, inheriting all the functionality of a particular class:

For example, a developer can add a new reference to his application solution Nomenclature Directories, or a new document Cash Report which will inherit the functionality of the class The documents.

Immediately after such an addition, new data types become available to the developer, the composition of which is determined by the belonging of the configuration object to one or another class of applied objects.

For example, after creating a new directory Nomenclature, the following data types become available:

  • DirectoryManager.Nomenclature,
  • DirectoryRef.Nomenclature,
  • DirectoryObject.Nomenclature,
  • DirectorySample.Nomenclature,
  • DirectoryList.Nomenclature.

The type system describes only the general "structure" of this type, the rules by which objects of this type will be formed. The specific name of the type, the composition of the properties and methods of the object will depend on how the developer will name the configuration object and what, for example, attributes, tabular sections, he will add to it.

At the same time, after creating a new accumulation register SalesCompany, the composition of the new data types will be different:

  • Accumulation RegisterSales ManagerCompanies
  • Accumulation RegisterSample.SalesCompanies
  • Accumulation RegisterList.SalesCompanies
  • Accumulation RegisterRecordSetSalesCompanies
  • Accumulation RegisterRecord.SalesCompanies
  • Accumulation RegisterKeyRecord.SalesCompany.

It should be noted again that these data types are not natively supported by the platform and exist only in a specific application solution.

Another point that should be emphasized is the easiest way to demonstrate with an example.

Let's say that two new directories have been created in the applied solution: Nomenclature and Prices... Despite the fact that both of these objects inherited the functionality of the corresponding class Directories, and for them in the applied solution the same set of data types was created, the "like" data types will be different data types. For example, ReferenceObject.Nomenclature Data type.

/
Creating and modifying metadata objects

Using Defined Types

Scope: managed application, general application.

1. Defined types are intended to define data types that describe frequently used entities or, with a high degree of probability, can change during the implementation of an applied solution. They allow you to reuse the described type or a set of types without specifying the composition in various places of the configuration (in attributes, properties of objects, forms, etc.).

See also the article on ITS: "Configuration Objects - Defined Types"

2.1. To define a simple type and its qualifiers that have an applied meaning that is used in various attributes, resources, form attributes, layouts, etc. within the framework of any subsystem or in the entire application solution. This ensures the same length, data accuracy at all points of use, and simplifies rework in the event of changing requirements.
For example:

  • Invoice Number- Line, length 30. Regulates the format of the invoice number in various documents: Arrival of goods and services, WriteBookShopping, Return of goods from customer and etc.
  • Delivery address- Line, 500. Textual representation of the delivery address in documents Order to Supplier, Shipping Address Carrier, in processing Sales Assistant, in the props Shipping Address Carrier document Request for Return of Goods from Customer and etc.

2.2. To define a composite type that is massively used in objects of a subsystem or in the entire application solution. The defined type guarantees the same composition (type) of data in all places of use, and also simplifies the refinement and implementation of subsystems in application configurations.

For example, the configuration includes a subsystem Interactions, which is intended for conducting correspondence by e-mail, registering calls and meetings. When implementing this subsystem, the developer made a decision on the composition of metadata objects that can act as "interaction contacts" - these are elements of directories Individuals, Partners, ContactPartners, and set this set of types in the defined type ContactInteractions provided in the subsystem. In turn, the defined type is massively used in the attributes of objects and forms of the subsystem (in documents A meeting, Planned Interaction- tabular section Participants, in document MessageSMS- tabular section Addressees, in document Phone call- props SubscriberContact, in general forms The address book, Select Contact- requisites Contact by Subject, in the layout parameter Hierarchy of Interactions document journal Interactions etc.) Otherwise, without using a defined type ContactInteractions it would be necessary to remove objects of the subsystem from support and set the required set of types in all the listed places.

2.3. When developing an embedded subsystem - to override the applied type, which will be refined during implementation.
For example, the type of subsystem Suppliers during implementation, it can be replaced with an applied configuration type Contractors.

3. It is incorrect to use defined types to set a "synonym" for an existing type, "substitute" entities, for local (not mass) use within one subsystem (configuration) without the need to be implemented in other configurations, only for reasons of ease of modification. As a rule, this indicates a design error or a methodologically incorrect choice of the initial type name.

We continue our acquaintance with the new functionality of 1C: Enterprise, which we started in the previous article of the series. After studying the materials in this article, you will learn:

  • What are defined types and how do I use them?
  • What is the Primary Roles configuration property used for?
  • How do I use the Form Client Event Handler Helper?
  • How and why are configuration dumping into XML files used?

Applicability

The article discusses the platform "1C: Enterprise" version 8.3.4.437, but its materials can be useful for those who work on older releases.

How to facilitate development in "1C: Enterprise 8.3"

We continue to consider the innovations in the 1C: Enterprise 8 platform aimed at facilitating configuration.

Defined types

A new object has been added to the 8.3 platform in the “General” configuration branch - Defined types.

This is a special configuration object that is designed to define a data type that describes a frequently used entity or, with a high degree of probability, can change during the implementation of an application solution.

For example, consider a composite type that includes a link to the “Contractors” and “Individuals” directories.

And this type in some developed configuration is often used as a measurement in the information register describing contact information, as an attribute in the document “Cash order”, etc.

During the implementation of such a configuration, the composition of this type can change - new objects can be added to it, and also vice versa - superfluous types can be excluded.

If instead of our new "defined type" we use a composite type in every place where such an entity is used, then we will have to change the composition of types everywhere. It is long, difficult, labor-consuming, there is an opportunity to forget about some props.

If you use a defined type, then only the definition of this type (and the program code that processes such fields) will need to be changed in the process of finalizing the applied solution.

All details for which the defined type is specified as the type will be changed automatically.

Here's another example of using a defined type.

For some of the details, there is a typing standard within the configuration. For example, we define a quantity as a number of length 15 with precision 3, and a sum as a number of length 15 with precision 2.

Suppose that a company needs to keep records of high-value goods with high accuracy of their weight.

Accordingly, we needed to increase the accuracy of the details to account for the quantity to 4 decimal places. These changes must be made simultaneously to all details of documents, register resources.

This is a simple task, but very time consuming and requires great care and perseverance of the developer.

When creating a new defined type, you only need to specify its type. Then, when creating the details of documents, register resources, you can select a link to the created defined type.

This approach allows you to guarantee the same data type (same length, precision, same composition for fields of complex type, etc.) in all places where it is used.

Then, if it is necessary to change the data type for all the details, you do not need to manually correct each attribute separately, it is enough to make changes to the corresponding defined type.

The type being defined can be made composite. However, there are restrictions on the use of this configuration object. Thus, the type being defined cannot be part of the value type of the chart of characteristic types, and also cannot be part of the composite data type of another variable.

Note that in the platform of edition 8.3.5, the possibilities for using defined types have been increased by expanding the set of types that can be part of the defined type.

No more changes were made in working with the defined type up to the current platform versions 8.3.10 / 8.3.11.

Main Roles configuration property

In platform 8.2, the root configuration element had the "Main role" property, in which the developer defined the role that will be used if no users are created in the infobase.

In the 8.3 platform, it became possible to specify several roles that will be used when determining access rights with an empty list of users. Accordingly, the property was renamed to "Main Roles".

Click on the image to enlarge.

Creating custom form client event handlers

When configuring a managed application, the developer must carefully monitor the context of program code execution using the appropriate preprocessor directives.

Since a limited set of data types and methods are available on the client, the developer often needs to create a client procedure from which to transfer control to the server.

The 8.3 platform introduces a wizard for creating client form event handlers.

Click on the image to enlarge.

Now the developer does not need to manually create the server method and indicate its call inside the client procedure, but can concentrate entirely on the implementation of the applied logic of the system.

Uploading configuration to files

Another innovation of the 8.3 platform is the ability to unload the entire configuration to disk as a set of files of a certain structure.

The configuration is always unloaded only in its entirety, without the possibility of filtering the unloaded objects.

To upload the configuration to files, select the Configuration - Upload configuration to files item in the menu, in the opened dialog select the directory where the files will be saved.

Configuration objects are uploaded as a set of XML files. Modules and text layouts are saved as TXT files. Pictures from the configuration are saved as image files (BMP, PNG, etc.). Help information is dumped into HTML files.

Click on the image to enlarge.

As you can see, the resulting files have common universal formats. There are a large number of different software products for editing them.

You can also use third-party version control systems. They allow you to store multiple versions of the same document, revert to earlier versions if necessary, and determine who made a change and when.

Edited files can be loaded back into the configuration using the Configuration - Load configuration from files menu item.

Working with the new loading / unloading functionality is also available using the LoadConfigFromFiles and DumpConfigToFiles command line parameters. For example, like this:

“C: \ Program Files (x86) \ 1cv8 \ 8.3.4.437 \ bin \ 1cv8.exe” DESIGNER / F “X: \ Platform8Demo” / N “Administrator” / DumpConfigToFiles “X: \ 1 \”

Earlier, back in the 8.2 platform, there was a mechanism for unloading / loading configuration files, which allowed for selective unloading / loading of some properties of configuration objects (modules, layouts and reference information).

It was noticed that by default the commands “Unload configuration files” and “Load configuration files” were excluded from the configurator in the 8.3 platform.

However, by customizing the main menu, you can display and use these commands on the menu.

The new mechanism for unloading the configuration into files always unloads the entire data for the entire configuration; the ability to configure objects for unloading is not provided, thereby ensuring the integrity of the configuration.

Regular forms and interfaces are uploaded in binary form (internal) and cannot be edited. The provider configuration is also not editable.

The rest of the objects are uploaded to files of universal formats. Essentially, the engine is targeting a managed application.

The new mechanism provides the developer with the ability to automatically process the configuration by launching the configurator in batch mode.

Also, now the configuration can be edited by external software using, for example, the XML format.

When unloading, additional processing of the configuration is performed: stuck links are removed, unused information is also not unloaded (for example, help for a non-existent language).

And when loading a configuration, its integrity is checked, it is not allowed to load files with non-unique identifiers, metadata objects, incorrect data type names, etc.

Note that since version 8.3.7 a new upload format has appeared, which is called "hierarchical". The old format became known as "linear". The choice of the format is available in the export to files window:

Since version 8.3.11, the "hierarchical" format has become the only one available for selection during interactive upload:

If you will use this functionality, we recommend:

  • first, use a "hierarchical" upload format;
  • secondly, use a platform not lower than version 8.3.8+, because starting with it, the speed of loading / unloading into XML files has been significantly increased.

In version 8.3.10, partial unloading of configuration into XML files has been supported. As a result, it became possible to use XML configuration dumping in conjunction with Git.

- we began to discuss what types of 1C values ​​and 1C type conversion are.

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

Since in the program code we work with values, we periodically need to know their type. Type 1C is always indicated in the metadata for the details - in directories, 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 ..."
  • Limitations when working in the interface
    Prohibition or permission for the user to enter values ​​of certain types of 1C in the field on the form.
  • Determining the actual parameter of a function / procedure
    If a function / procedure parameter can be of any 1C type, then you need to define it in order to get the value correctly.

Type 1C can be obtained:

  • Determine the type of actual value 1C
  • Object values ​​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 the metadata - you can get the 1C type as it is indicated in the metadata in the configurator.

Types of 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 1C value using the TypeZnch (Variable) function

To understand what type of 1C this function returned, you need to specify the Type we need ("TypeName")

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

What types should I write for TypeName?

Basic types

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

For example:
Znch = 12;
If TypeZnch (Znch) = Type ("Number") Then
ElseIf Znch = Type ("String") Then
ElseIf Znch = Type ("Date") Then
ElseIf Znch = Type ("Boolean") Then
EndIf;

Database types

1C stores data in a database, but not as separate records, but as objects.

Most of the stored objects (including: directories, documents, enumerations, business processes, tasks) are available as an Object (for editing and writing) and as a Reference (for reading). See References and Objects for details.

For example:
Znch = Directories.Organizations.EmptyRef ();
If TypeZnch (Znch) = Type ("DirectoryLink.Organizations") Then
ElseIf Znch = Type ("DirectoryObject.Organizations") Then
ElseIf TypeZnch (Znch) = Type ("DocumentLink.Arrival of Goods") Then
ElseIf Znch = Type ("DocumentObject.Goods receipt") Then
EndIf;

Registers can be of various types. Register type name is compound:
RegisterTypeAccessType.RegisterName

Types of 1C registers:

  • Information
  • Accumulation
  • Accounting departments
  • Calculation.

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

  • Record Set
  • List
  • Sample
  • Recording
  • KeyRecords.

Total, example:
IfTypeZnch (Znch) = Type ("InformationRegisterList.RegisterName") Then
ElseIf Znch = Type ("AccumulationRecordRecordSet.RegisterName") Then
EndIf;

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

Such types of 1C are indicated by their name (in one word, without spaces). For example:
If TypeZnch (Znch) = Type ("Array") Then
ElseIf Znch = Type ("ListValues") Then
EndIf;

Determination of the value of the 1C reference type

Work with all database objects (reference books, documents ...) is carried out through links. For example, if we want to make a props in a document - a reference book, then its type 1C will be "ReferenceLink.Reference name".

For example:
Value = Directories.Organizations.EmptyRef ();
If Dictionaries.TypeAllRefs (). Contains (TypeZnch (Value)) Then
// this is a reference
ElseIf Documents.AllLinkType () .Contains (ZnchType (Value)) Then
// this is a document
EndIf;

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

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

For example:

Obtaining available types of 1C

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

  • Fat client form field
    Form Elements.FieldName.Value Type
  • Field on a thin client form (exception: called AvailableTypes)
    Elements.Fields.AvailableTypes
  • Column of the table of values, tree of values
  • Form props
  • Selection element

How to work with this list of 1C types in the field. Value Type - see "Description of Types" in the "1C Language" section.

Working with types of 1C attributes in configuration metadata

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

Basic methods:

  • Call the Metadata () method for the 1C object, which returns the metadata of a specific object and then work with the list of attributes (and attributes of the tabular section)
    Documents.Goods receipt.EmptyLink (). Metadata (). Requisites
  • Use the global variable "Metadata", which returns all configuration metadata, and then go to the details of a specific object
    Metadata.Documents.Incoming Goods.Attributes

An 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 filter of types 1C

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

  • List of Values ​​(.Available Values)
  • 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 a Value Type and we cannot change it, but when adding a column using the Add () method, you can specify a list of available 1C types as the second parameter.

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.

Top related articles