Custom presentations for materials and services
Let us use the MaterialServiceType attribute for specifying custom presentations for materials and services in 1C:Enterprise interface.
Material and service presentations are displayed in all fields that refer to MaterialsAndServices catalog items. This includes document tabular section fields, information register fields, accumulation register fields, and more.
As with any catalog item, the default material or service presentation is defined by the Default presentation property. The default property value is As description (fig. 10.4).
Fig. 10.4. Default presentation property of a catalog
That is why the Material or service column in the document tabular section shows the material or service names instead of references (fig. 10.5).
Fig. 10.5. Services document
Let us modify the view of references to MaterialsAndServices catalog items so that they display the item type: material or service.
In Designer mode
The generation of configuration object presentations consists of two stages: first, defining the attributes that affect the presentation, and then the generation itself. You can use the following object manager event handlers for this: PresentationFieldsGetProcessing and PresentationGetProcessing.
- In Designer, in the configuration object tree, right-click the MaterialsAndServices catalog and click Open manager module.
- Add the procedures from listings 10.1 and 10.2 to the manager module.
Listing 10.1. Procedure PresentationFieldsGetProcessing()
Procedure PresentationFieldsGetProcessing(Fields, StandardProcessing) StandardProcessing = False; Fields.Add("Description"); Fields.Add("MaterialServiceType"); EndProcedure
Listing 10.2. Procedure PresentationGetProcessing()
Procedure PresentationGetProcessing(Data, Presentation, StandardProcessing) StandardProcessing = False; If ValueIsFilled(Data.MaterialServiceType) Then Presentation = Data.Description + " (" + Lower(String(Data.MaterialServiceType)) + ")"; Else Presentation = Data.Description; EndIf; EndProcedure
Now let us examine this script.
The PresentationFieldsGetProcessing handler describes the attributes that affect the document presentation. First, the handler sets the StandardProcessing parameter to False, and then it adds the required catalog attributes to the Fields array. Note that if StandardProcessing is not set to False, the Fields array contains the attributes used to generate the default object presentation (in this case it is the Description attribute).
The PresentationGetProcessing handler describes the generation of the Presentation parameter based on the array of fields specified in the previous handler. The data required to generate the presentation is passed in the Data parameter that has Structure type. First, StandardProcessing is set to False, and then the material or service presentation is generated by adding the type enclosed in parentheses to the description. Note that if StandardProcessing is not set to False, the platform attempts to generate the default object presentation based on the data that is passed to the handler.
In 1C:Enterprise mode
Let us test the changes that you made.
- Run 1C:Enterprise in the debug mode.
- Open the Services document and ensure that the material or service presentations are generated according to the algorithm that you specified (fig. 10.6).
Fig.10.6. The Services document
You can use this method to set custom presentations not only for catalogs, but also for documents, charts of characteristic types, charts of accounts, and other configuration objects.