How to set up smartphones and PCs. Informational portal

1c set the type of the form attribute. Database types

- classification of values ​​​​(i.e. data) by 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 the 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 rigidly specifies what type of data it can store. The same with functions, procedure parameters, etc. In the 1C metadata, the type of the details is strictly indicated (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 hard 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 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 the value 1C, which means that 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 1C NULL value that a query can return when trying to get data from the database, if it was not possible to get data (more precisely, the value in the NULL field means that the field in the database is “not filled”).
Selection = Query.Execute().Select();
While Selection.Next() Loop
If Selection.Field1 = NULL Then
Proceed;
EndIf;
EndCycle;

1C value types

As "variables" it is possible to use:

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

The requisite can have a composite type 1C, that is, several possible ones. The assignment of the value 1C by the user in this case can be two-stage:

  • Selecting the type of value 1C from the available
  • Choice of value 1C.

By default, this attribute has the value 1С Undefined. When the 1C type is selected, but the 1C value is not yet selected, the empty value of this 1C type (0 for number, null reference for 1C reference types, see below). And finally, then - the value of 1C. From the assignment program, the value is made directly, without an intermediate choice of type 1C.

It is possible to determine the type of value 1C in several ways:
//method 1 - comparison with known 1C types
Variable1 = 12;
If TypeValue(Variable1) = Type("Number") Then
//…
ElseIf TypeValue(Variable1) = Type("CatalogReference.CatalogName") Then
//…
EndIf;

Type conversion 1C

The value 1C of simple types 1C can be converted using the operator - the name of the 1C type:
//into a 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 a string
ValueString = String(22);
ValueString = AbbrLp(22);
ValueString = Format(22, "YY=0");

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

Type conversion 1C - values ​​​​of complex types 1C

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")

As the line "Settings" you need to specify the required format 1C. Such settings are specified in a special coded form. Consider the most commonly used settings:

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

An example of displaying a date 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 specify the order of the parts of the date and the symbols for their separation, you must use the setting:
DF = "dmg hms"

Accordingly, "dmg" is the day, month and year, and "hms" is hours, minutes and seconds. Any of these parts can be skipped. The order is any. The characters specified between the parts will be used as separator characters.

Date Partial Character M. b. specified several times in a row, the appearance of this part of the date depends on this, for example, “d” or “dd” or “dddd”.

Deciphering parts of the date:

  • d - day
    o small "d"
    o 1 to 4 times
  • M - month
    o big "M"
    o 1 to 4 times
  • d - year
    o small "g"
    o 1 or 2 or 4 times
  • h - hours
    o small "h" - 12 hour format
    o big "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 - AM/PM display for 12 hour format
  • k - quarter.

An example of displaying a date with rules:

Number format in 1C language
Unlike date formatting, where everything is quite simple, there are many options for formatting a number. Here are the ones that are most commonly used.

The first "problem" is related to the default grouping of digits in numbers of 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 a beautiful and understandable output to the user, but for service needs. This can be influenced by the "CH" parameter, for example:

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

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

For 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 make the "CHN" parameter:
Format(0, "HN=""""")

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

Working with 1C types is often used:

  • Conditions in the program
  • Different actions depending on the type of value 1C in the construction "If ... Then ..."
  • Restrictions when working in the interface
  • Prohibition or permission for the user to enter values ​​of certain types of 1C into 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
  • Value-objects have properties that specify 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 of 1C can be divided into three types:

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

Definition of type 1C and comparison of types 1C

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

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

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

What types to write as TypeName?

Basic types

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

For example:

Value = 12 ; If TypeValue(Value) = Type("Number" "String" ) Then ElseIf Value = Type("Date") Then ElseIf Value = Type("Boolean") Then EndIf;

Database types

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

Most of the 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 details.

For example:

Znch = Directories. Organizations. EmptyReference() ; If TypeZnch(Znch) = Type( "DirectoryLink. Organizations") Then ElseIf Value = Type( "DirectoryObject.Organization") Then ElseIf TypeZnch(Znch) = Type( "DocumentReference.Receipt of Goods") Then ElseIf Value = Type( "DocumentObject.Receipt of Goods") Then EndIf;

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

Types of 1C registers:

  • Information
  • Savings
  • Accountants
  • Calculation.

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

  • RecordSet
  • List
  • Sample
  • Recording
  • RecordKey.

Example:
If TypeZnch(Znch) = Type("RegisterInformationList.RegisterName") Then
ElseIf Value = Type("AccumulationRegisterRecordSet.RegisterName") Then
EndIf;

Types 1C

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 a word, without spaces). For example:
If TypeZnch(Znch) = Type("Array") Then
ElseIf Value = Type("List of Values") Then
EndIf;

Determining the value of the reference type 1C

Work with all database objects (directories, documents ...) is carried out through links. For example, if we want to make a prop in a document - a directory, then its type 1C will be "ReferenceReference.DirectoryName".

For example:

Value = References. Organizations. EmptyReference() ; If directories. TypeAllReferences() . Contains( TypeValue(Value) ) Then //this is the ElseIf reference Documents. TypeAllReferences() . Contains( TypeValue(Value) ) Then //this is a document EndIf;

Working with 1C types in a request

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

To check the type of a field in a 1C 8.3 query, you can use the query language function VALUE TYPE(<Поле>).

WHERE VALUE TYPE(Table.Sum) = TYPE(NUMBER)

Function TYPE(<Имя типа>) gets the type by its name. Primitive type names: Number, String, Boolean, Date. The names of reference types are built according to the following principle: Document.Realization of Goods/Services or Catalog.Nomenclature.

CHOOSE Self-supporting Turnovers. Subconto1, Self-supporting Turnovers. Subconto2, Self-supporting Turnovers. Subconto3, Self-supporting Turnovers. SumTurnover, SELECT WHEN VALUE TYPE(Self-supportingTurnovers. Subconto3) = TYPE(Document. Sales of Goods/Services) THEN "Sale" WHEN VALUE TYPE(Self-supporting Turnovers. Subconto3) = TYPE(Document. IncomingCash order) THEN "PKO" WHEN VALUE TYPE = Document3 . Outgoing Cash Order) THEN "RKO" ELSE "Other document" END AS A Document Type of Settlements FROM Register Accounting. Self-supporting. Turnovers(& StartPeriod, & EndPeriod, Registrar, Account = & Account6201 , , , , ) AS Self-supporting Turnovers For fields of reference type, there is another way to check using the REFERENCE operator.

CHOICE WHEN Self-supporting Turnovers. Subconto3 LINK Document. Realization of Goods and Services THEN "Sales" WHEN Self-supporting Turnovers. Subconto3 LINK Document. Receipt Cash Order THEN "PKO" WHEN Self-supporting Turnovers. Subconto3 LINK Document. ExpenditureCashOrder THEN "RKO" ELSE "Other document" THE END

Getting available types 1C

A set of objects has a property.ValueType, which contains a list of 1C types:

Field on the fat client form
FormElements.FieldName.ValueType
A field on a thin client form (exception: called AvailableTypes)
Elements.FieldName.AvailableTypes
Column of value table, value tree
Form props
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 1C attribute types 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 the 1C attribute.

Main methods:

Call the Metadata () method of the 1C object, which returns the metadata of a specific object and then work with the list of details (and details of the tabular part)

Use the global variable "Metadata", which returns all configuration metadata, and then go to the details of a particular object

Metadata.Documents.Receipt of Goods.Details

The attribute has a property.Type that 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 type filter 1C

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 editable, it is possible to specify the filter in the object method. For example, a table (tree) column has values.ValueType 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 the list of 1C types for the filter - the list of 1C types is used, how to work with it - see "Description of types" in the "Language 1C" section.

Attention! Here is a trial version of the lesson, the materials of which may not be complete.

Login as a student

Sign in as a student to access school content

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

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

The query language has a whole class of functions and operators for working with attribute types. Let's take a look at them.

VALUETYPE function

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

Now let's take a look at the props. Distinguishing Feature at the directory Cities:

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

If we try to fill in the value of such an attribute in 1C:Enterprise mode, the system will ask us what type the input value will be:

And only after our choice will allow you 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 ( Distinguishing Feature) values ​​of different types (String, Colors or Flavors).

You can verify 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 located.

Here the feature value is a reference element Tastes:

Here the line:

And here, in general, an element of the directory Colors:

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

I wonder how the function will behave VALUETYPE on props DistinctiveElement, which has a composite data type:

This is already very interesting. Let's deal with each line separately.

The feature value type for the Russia element is 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.

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

The value type of the distinguishing feature for Perm is Tastes. So it is, because the value of the distinguishing feature scored in the database for the city of Perm is a link to the directory element Tastes.

For Krasnoyarsk, the feature type is equal to Colors, because the value selected in the database is a reference to a dictionary element Colors.

For Voronezh, the feature type is equal to Line, because the value entered in the database is a normal string.

India is a group again, so the meaning is missing. And the type of the missing value, as we remember, is NULL.

And here's the thing. If you go to the directory element Cities with the name Sao Paulo, you will see that the field Distinguishing Feature completely unfilled. It is empty. BUT all empty fields of a composite type have a special meaning UNDEFINED .

FROM UNDEFINED we also meet for the first time. Meaning UNDEFINED used when you want to use an empty value that does not belong to any other type. This is just our situation. A 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 OF, BOOLEAN), or the name of the table whose reference type you want to get.

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

Sounds hazy, doesn't it?

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

Suppose we want to select all directory entries Cities, which have a composite attribute Distinguishing Feature has a value of type LINE:

Now let's select all records that have attribute values Distinguishing Feature are references to reference elements Colors(table Reference.Colors):

Retreat

As you remember, some elements of the directory Cities do not have props Distinguishing Feature. Function VALUETYPE for such elements gives NULL.

How it is possible to make selection of such elements in request? There is a special logical operator for this. IS NULL(not to be confused with the function IS NULL which we will discuss below). You are reading a trial version of the lesson, full lessons are located.

Here is an example of its use:

Fine. But you noticed that there is no Sao Paulo element here, props value type Distinguishing Feature which was also issued NULL. Why did it happen?

And the thing is that the situation for groups (Russia, India, Brazil), for which filling in the details Distinguishing 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 attribute is possible, but it is simply not filled in and, as we remember, is equal to the special value UNDEFINED.

To select all records that have props Distinguishing Feature present but not filled, another construct should be used:

But comparing with UNDETERMINATED to define empty (not populated) props will only work for composite types.

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

Boolean operator REFERENCE

For example, let's choose from the directory Cities only those records that have the value of a composite attribute Distinguishing Feature are a reference to a reference element Tastes:

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

Function ISNULL

The function is intended to replace the value NULL to another value.

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

Like props Distinguishing Feature for directory groups Cities:

Function IS NULL will help us output another value if this value is equal to NULL. You are reading a trial version of the lesson, full lessons are located. Let in this case it will be the line "There is no such attribute!":

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

EXPRESS function

This function is only for fields that have a composite type. A great example of such a field is the property Distinguishing Feature for directory elements Cities.

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

For field Distinguishing Feature such valid types are LINE, Reference.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 Distinguishing Feature to type Reference.Colors:

As a result, all element values ​​that had the type Reference.Colors, remained filled and turned out to be reduced 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 OF) or to a reference type. You are reading a trial version of the lesson, full lessons are located. 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 generate an error.

Take the test

Start test

1. Choose the most correct statement

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

3. To determine the type of attribute value, the function is suitable

4. Unfilled composite type attributes matter

Top Related Articles