Generating data based on other data
You can use this feature to generate new objects (such as documents, catalogs, or charts of characteristic types). We will explain this feature on the example of document generation, which is the most common use case.
For each Document configuration object you can allow its generation based on other database objects. And the document itself can serve as a basis for generation of other objects.
The operations that fill document attributes during the document generation must be described in the object module of the document, in the Filling event.
You can either do it manually or use the generation settings wizard that offers visual tools for handler script generation.
In this example a Services document is generated based on a Customers catalog item.
Creating a document generation command
Generated objects
While the platform allows the generation of objects based on other objects, it has no special means to analyze chains of related objects. We will provide a few tips on the subject that you can use in your development.
To form chains of related objects, add an auxiliary attribute to each generated object. The attribute will store a reference to the basis object. Then create a FilterCriterion object for filtering by specific values of that attribute.
Then, to get all generated objects, you can simply assign the required value to the filter criterion.
Understanding filter criteria
The FilterCriterion configuration object is used to establish the rules for filtering objects.
You can use it to search for data of any kind. For example, you can apply a filter to find all documents whose attributes or tabular sections include a specific contractor.
You can apply multiple filters (for example, filter only posted documents or only documents belonging to a specific time interval).
Getting generated objects
Since the task of getting all the objects generated on the basis of some other object comes up most often in document analysis, we will illustrate the methodology described above using the example of getting a list of documents created on the basis of a Customers catalog item.
In Designer mode
Let us implement the document generation.
- Open the configuration object editor for the Services document.
- Add a document attribute named BasisObject of CatalogRef.Customers type.
Creating the attribute is not required for document generation, it is only needed for building a chain of dependent documents in the future.
Let us specify the documents that can serve as a basis for generating the Services document, and the list of documents that can be generated based on the Services document. - On the Generation tab, in the Can be generated based on pane, click the Edit List item
button and select the Customers catalog (fig. 26.5).
Fig. 26.5. Defining the assortment of objects that can serve as a basis for the document generation - Click Generation settings wizard.
Let us specify the attribute values for a document to be generated. - Click Fill Expressions (fig. 26.6).
Fig. 26.6. Filling attribute values for a generated document
Note that the wizard suggests using the FillingData.Ref value for filling the BasisObject attribute. In this scenario this record is redundant because a reference to a catalog is passed as a basis.
However, in general, the Filling event comes up when an object is created based on a passed value (which might not have the reference type). - Click OK.
This generates the Filling event handler script in the document module (listing 26.12).
Listing 26.12. Filling event handlerProcedure Filling(FillingData, StandardProcessing) //{{__CREATE_BASED_ON_WIZARD // This fragment was built by the wizard. // Warning! All manually made changes will be lost next time you use the wizard. If TypeOf(FillingData) = Type("CatalogRef.Customers") Then // Filling the headline Customer = FillingData.Ref; BasisObject = FillingData.Ref; EndIf; //}}__CREATE_BASED_ON_WIZARD EndProcedure
As you can see, an If... condition is generated for each type of basis object, and the attributes of the new document are filled within that condition.
In 1C:Enterprise mode
Let us test the document generation.
- Start 1C:Enterprise in the debug mode.
- Open the list of customers.
Note that the command bar of the Customers catalog list now contains the Generate button. - Select a customer, click Generate, and click Services.
This creates a Services document where the Customer field is filled with the selected customer (fig. 26.7).
Fig. 26.7. Generating a Services document based on a customer - Enter a few more documents based on customer Peter Smith.
In Designer mode
Let us implement the filter.
- In the configuration tree, expand the Common branch and create a FilterCriterion configuration object named Services.
- On the Data tab, select the criterion type: CatalogRef.Customers.
- On the Content tab, select the BasisObject attribute of the Services document (fig. 26.8).
Fig. 26.8. Content of the Services filter criterion
This adds the command that opens the filter criterion to the navigation panel of the Customers item form (to the Go to group). - Create the Customers catalog item form and then, on the Command interface tab, set the visibility of the Services command (fig. 26.9).
Fig. 26.9. Command that opens the filter criterion from the Customers catalog item form
In 1C:Enterprise mode
Let us test the filter.
- Start 1C:Enterprise in the debug mode.
- In the customer list form, select customer Peter Smith.
Previously you created a few documents based on this customer. - Open the customer form.
The navigation panel now has the Services command. This command opens the list form of the filter criterion, where a filter by the selected Customers catalog item is applied. - Run this command (fig. 26.10).
Fig. 26.10. The Services filter criterion list with a filter by customer
The resulting list contains the Services documents generated based on customer Peter Smith. Double-clicking a document opens it.