Predefined element 1C. Use predefined elements. Work with predefined values \u200b\u200busing the predetermined function ()

Specifies for the version of the 1C platform: Enterprise 8.3.3 and above without a compatibility mode with version 8.2

1.1. In reference books, bill plans, features and plan plans for calculation species, it is possible to create predefined elements automatically or programmatically.

1.2. In most cases, predefined elements are recommended to be created automatically because they are constantly needed and it is necessary to simplify the appeal to these elements from the code.
For example, a predetermined country Russia in the directory Countries of the world, predetermined access band profile Administrator etc.

For this

  • in the property of the reference book, the plan of accounts, the plan of the species of characteristics or plan of calculation species must be set to Auto (by default), and not to allow program calls of the method Installation recommended by the predictional These objects to switch this mode.
  • to disable the deletion of predefined elements by users, turning off the following rights in all roles (disabled by default):
    • Interactive rehabilitation
    • Interactive Power SuppliesPredentials
    • InteractiveNateIntepometectivationsPretested
    • Interactive rehabilitation

1.3. An exception is the daughter of rib nodes, in which predefined elements are not automatically created (and not updated when changing in metadata), but must be transmitted from the main node along with changes in configuration.

Wherein:

a) the configuration must provide the exchange message to the subordinate Rib node before performing another application code, which refers to the predetermined elements received from the main node;

b) in the application logic application logic from the main node (event handler Indiscriminates reported, object registration rules) appeals to predefined elements should be avoided, since there is no guarantee that they have already been downloaded from the exchange message;

c) IB update handlers code, which processes predefined elements, should not be performed in subordinate rib nodes:

If billing. Study () \u003d indefinitely then // Fill predefined elements // ... ended;

When used in the configuration of the Data Exchange Libraries of the Standard Subsystems (BSP) version 2.1.4 and above, the requirements (A) and (b) are removed.

1.4. For tables with predefined elements that are not part of the RIB exchange plan (and on which other tables are not referred to, which are part of the RIB exchange plan), it is recommended to establish a property. UpdatePretested In value Upgraded automaticallyAs well, when you first start the subordinate RIB node to establish an automatic update in data using a call:

Directories. AMPLEMENT\u003e. Installation recommended perhetted (updateRended-defined. Upgraded automatically);

2. In some cases, predefined items are not required to create automatically if their presence depends on any condition: the functional option is enabled, the mode of operation of the program, etc.

For example, those or other predefined types of calculations in terms of calculation species Accrued depend on the values \u200b\u200bof functional options Use subsurnese industry staff, ADDITIONALLYAGEMAGE and etc.

For this

  • in the property UpdatePretested Director, account plan, Plan of species of characteristics or plan of calculation species need to be set to "Do not update automatically"
  • provide code for creating (and marked invalid) a predefined element depending on business logic, for example:
If you get functions ( "Understand vehicles") Then the accrual object \u003d PlansWyduce. Accrued. Copyright (); Accrued. Pedestinated name \u003d "salary"; // ... Calculation. Write down (); Ended;
  • take into account in the application code the absence of predefined elements in IB. Otherwise, when accessing a non-existent predefined element, an exception will be caused from the code or query text:
. . . \u003d PlanvidaCet. Accrued. Salary compass; . . . \u003d Predestination ( "PlannavidaChthet. Costs. Favoris") ;

When using the library configuration of the standard subsystems (BSP) version 2.1.4 and above, it is recommended to use the function Predefined element General module General OdnationClinerverwhich returns Undefined For non-existent in IB predefined elements.

Attention! Before you, the introductory version of the lesson, the materials of which may be incomplete.

Sign in as a student

Log in as a student to get access to the materials of the school.

Query language 1C 8.3 for novice programmers: Function value

Function VALUE designed for appeal In the text of the query to the values \u200b\u200bof system transitions and predefined data.

What else for enumerations and predefined data, you ask. Let's do everything in order.

Listing

Listing - this is an applied object (you remember that there are still exist Directories and Documentation). Why did he need?

The fact is that the listing is a special object. Unlike directory and documents all possible enumeration values \u200b\u200bare set at the configuration stage. and cannot be modified in the user mode.

Reputability is their chief trump card. These are peculiar database constants.

And if a programmer in configuration mode created a listing named Floorand values Male and Female, when writing a program, it can be confident that in the future the values \u200b\u200bof this listing will not change. Therefore, it can safely contact these values \u200b\u200bfrom the code.

Imagine what will happen if he tries to use the directory for these purposes?

First, some user will take and add some "Martian floor".

Secondly, the other user will take and remove one of the already existing sexes or his name will change.

And the program will break from this, because for her work it is necessary that there are exactly two sexes and precisely with the names of the "male" and "female".

Here for such cases, just exists of enumerations: so that once (even at the configuration stage), it is hard to set all possible options for values \u200b\u200band further use them in the program code.

Let's consider an example of such a listing in our database. You are reading a familiarization version of the lesson, full lessons are located.

Here it is our listing named Floor. What values \u200b\u200bdoes it take?

Just two values. With the names of "male" and "female". What we need.

Where can we further use this listing? Well, of course, in the directory Customers. Please note that a new props appeared on his list. Floor and type Listing. POL.:

Thus, when filling out the client's card, we can choose only two values \u200b\u200bof male and female as a client's floor:

Now let's make a request that chooses customers and their floor from the base:

And now let's change the request to remain only men. If we try to write something like:

i will not get anything:

Because it is impossible to contact the values \u200b\u200bof the listing. Need to handle using the function VALUE:

So, one of the tasks of the function VALUE - Use in queries of enumerations.

Predefined data

I will show better on the example what is predefined data for reference books. You are reading a familiarization version of the lesson, full lessons are located.

In our database "Deli" (in user mode), open the "Units of Measure" reference:

Take a look at its elements. See Yellow mugs next to some of the elements? These items (who have mugs) and there predefined data.

In general, if any element of the reference book is predetermined (that is, it stands the yellow circle on it), then this is a special element.

First, it means that the element was created at the configuration stage of a programmer (in our case, these are elements with codes 1, 2 and 3).

And, secondly, this means that this item is very important for the functioning of the program. What to him (or rather to its predefined name), some code is tied in the database.

That is why it is easy to remove such an element. Try to mark it for removal:

Let's go into configuration mode and see where these most predetermined elements (in this case, for the measurement units directory) are created:

Here they are all our predefined elements for a reference unit of measurement. Please note that all predefined elements have a special name that is not displayed in user mode.

For the item with code 1, this is the name of the ton, with code 2 - grams and so on. This name is called predefined element name And it is for this name that you can contact it from the code (or from the request in our case).

You ask why it was not to make units of measurement simply by listing with ton elements, grams and a pack? And all because in this case it is important to us that the reference book units always contain some specific items (tons, grams and pack), but at the same time we do not want to prohibit the user to add some of their own elements (kilogram, pieces etc). You are reading a familiarization version of the lesson, full lessons are located.

Therefore, predefined elements are certainly more suitable here than enumerations.

And access our predefined elements from the request we can use the already familiar function to us VALUE:

Pass the test

Start test

1. The values \u200b\u200bof the enumerations are set

2. To store the list of warehouses on the company it is suitable

3. To store the list of units of measurement in the warehouse, the type will suit

4. For storing tax rates, the list of which should not be changed by the user, will suit the type

5. To contact the list of enumeration value, the function is suitable

6. For storing tax rates, the list of which will change by the user will suit the type

7. Predefined data happens to

Everyone knows the difference between predefined elements from ordinary: "predefined items are created in the" Configurator "mode and cannot be removed in 1C mode: enterprises." In user mode, it is possible to distinguish the predefined element from the added users by a special icon (see the following screenshot).

Basically, predefined elements are created by the developers to establish algorithms on them in various configuration objects. For example, in the configuration of "Management of the Production Enterprise" in the "Quality" directory, the developers have been added a predefined element "New".

This element is used in many configuration modules. So in the document "Receipt of goods and services" when performing in all registers, where there is a "quality" measurement, the value of the predefined element is substituted. The following is a listing of filling out the table of conducting a register "Products":

// Products for registers Products. Nation \u003d movement. Products; If the type access control \u003d enumeration. Promotions. Skold then // Receive the table of values \u200b\u200bthat coincides with the registry set structure. Facilities \u003d nominations. Unload (); // Fill the movement table. Output. DownloadingAvtablitsy (tablesPotes, tables); // missing fields. Facility. Filling out (organization, "organization"); Facility. Filling out (undefined, "commission agent"); Facility. Failure (References. Quality. New, "quality"); // Fill the quality from the predefined element

Thus, the characteristic features of predefined elements and their purpose is quite simple. Consider how they are stored in the database tables and its difference from conventional elements.

Differences

The test configuration creates a reference book "Goods". It creates a group "Test elements". The contents of the group you could see on the screenshot at the beginning of the article. For the reference book "Goods" in the SQL-database there is a corresponding table "_reference37" with the following structure:

But how to determine the compliance of the details of the configuration tree and fields in the SQL table?

We use the standard method of global context "Great Structural Based ()", which will return to us the table of values \u200b\u200bwith the description of the tablestores.

In the table of the "Field" values, we see matching the SQL tables and the object details in the metadata tree. In our example, we consider the structure of the reference book "Goods". All directories have a standard props "predetermined" boolean type, which is installed in truth for predefined elements:

According to the table with the storage structure of the reference book in the database, we unambiguously we can say that the "predefined" field matches the "Ismetadata" field. If we review the contents of the "_reference37" table in the SQL-database, we will see the following:

In the entry for a predefined item, the value of the "Ismetadata" field is set to "0x01", which corresponds to the flag of the truth. For conventional items, the value is set to "0x00". This is the main difference between predefined elements from ordinary. All other fields are stored in the database, similar to the fields of conventional elements added by users.

Predefined elements can be found very interesting purpose. With their help, you can prohibit delete / refer to delete a group of items in the directory and other objects where you can add them. If we try to delete or mark on deleting a group "Test elements". I will get such errors:

Thus, predefined elements make the group into which they are placed, also "predefined".

Completion

Predefined elements are an integral part of most configurations. Their use simplifies the development and makes the construction of the functionality logically more "slim" and solid.


Top.