In Designer mode
Your application logic might require custom attribute fill checks. In this scenario, if the Fill check property of an attribute is set to Display error, you can use 1C:Enterprise script to remove the attribute from the array of attributes to be checked and then implement a custom check. Alternatively, you can add an attribute that is not normally checked to the array of attributes to be checked.
1C:Enterprise-based fill checks for configuration objects are executed in FillCheckProcessing() event handlers that are located in object modules. A FillCheckProcessing event handler is called every time an object form is saved or a document is posted. Fill checks for values that are entered interactively must be performed in this event handler instead of when the object is being saved.
- Open the Services document module and add the procedure shown in listing 27.4.
Listing 27.4. FillCheckProcessing event handler
Procedure FillCheckProcessing(Cancel, AttributesToCheck) Index = AttributesToCheck.Find("MaterialsAndServices.PropertySet"); If Index <> Undefined Then AttributesToCheck.Delete(Index); EndIf; Index = 0; For Each CurRowMaterialOrService In MaterialsAndServices Do If CurRowMaterialOrService.MaterialOrService.MaterialServiceType = Enums.MaterialServiceTypes.Material Then If Not ValueFilled(CurRowMaterialOrService.PropertySet) Then Message = New UserMessage(); Message.Text = "The ""Property set"" column is not filled in row " + String(Index+1) + " of the ""Materials and services"" list"; Message.Field = "MaterialServiceList[" + String(Index) + "].PropertySet"; Message.SetData(ThisObject); Message.Message(); Cancel = True; EndIf; EndIf; Index = Index + 1; EndDo; EndProcedureFirst the procedure searches the AttributesToCheck array for the PropertySet tabular section attribute. This array is passed to the event handler and contains all the attributes that have the Fill Check property set to Display error. If the PropertySet attribute is found, it is deleted from the array because a custom check is performed for that attribute.
Next the procedure iterates through the document tabular section rows and generates an error message for each tabular section row that has an empty value in the PropertySet column.
Setting the Cancel parameter to True means that the document is not posted if at least one row that contains a material has an empty PropertySet value. If you comment this script line out, error messages will be displayed but the document will be posted.
To simplify the example, we used the MaterialsOrServices.MaterialOrService.MaterialServiceType call, though using a query is optimal here. This issue has been discussed in detail in lesson 14 so we will not discuss it here again.