In Designer mode
The first thing you need to do is modify the modules of all the objects that are involved in exchanges (these objects include documents, catalogs, and charts of characteristic types).
After the changes document numbers, catalog codes, and chart of accounts codes will be generated based on the value of the NumberingPrefix constant to ensure that such numbers and codes are unique.
Let us keep the function that generates the numbering prefix in a common module because in the future you might need to change the algorithm used to generate document prefixes.
- Add a common module named Exchange.
- Add the function shown in listing 24.1 to the module.
Listing 24.1. Function that generates a number prefix
Function GetNumberingPrefix() Export Return Constants.NumberingPrefix.Get(); EndFunctionAs you can see, the function merely returns the value of the NumberingPrefix constant.
Now let us update the Customers catalog.
- In the configuration object tree, right-click the Customers catalog and then click Open object module.
- Add the OnSetNewCode event handler as shown in listing 24.2.
Listing 24.2. OnSetNewCode event handler
Procedure OnSetNewCode(StandardProcessing, Prefix) Prefix = Exchange.GetNumberingPrefix(); EndProcedureThe OnSetNewCode event occurs when a new code is set for a catalog item. Note that you are creating this script in the object module instead of the form module because this event occurs for the object in general instead of some particular form.
Prefix is the second parameter passed to the handler. A prefix is populated in this procedure, and the platform generates a code based on the prefix.
The event handler calls a function of a common module. Since the module is not global, you address the function using the module name and the function name: Exchange.GetNumberingPrefix. In this procedure you assign the value of the NumberingPrefix constant to the prefix.
- Add similar handlers to all the catalogs and charts of characteristic types involved in exchanges:
- For all these objects and for the Customers catalog, in the configuration object property palette increase code length to 11 characters.
Now let us update the documents.
- In the GoodsReceipt document module, add the OnSetNewNumber event handler as shown in listing 24.3.
Listing 24.3. OnSetNewNumber event handler
Procedure OnSetNewNumber(StandardProcessing, Prefix) Prefix = Exchange.GetNumberingPrefix(); EndProcedure
- Add similar handlers to all the documents involved in exchanges (in your configuration it is only the Services document).
- For both documents, in the configuration object property palette increase the number length to 11 characters.
This completes the preparations for existing configuration objects, and you can move on to the development of data exchange procedures.