In Designer mode

Creating data exchange procedures

Let us create the central part of a data exchange algorithm: the exchange plan.

  1. In the configuration object tree, expand the Common branch and add an ExchangePlan configuration object named Branches.
  2. In the Object presentation field, enter Branch.
  3. On the Data tab, create an exchange plan attribute named Main, of the Boolean type (fig. 24.2).

    Fig. 24.2. Exchange plan attribute

    You will need this attribute to resolve collisions during data exchanges. A collision is a situation where a data exchange object is simultaneously modified in two nodes.

    In this case you will look into the value of the Main attribute and confirm the changes only if they are made in the main node. In the event of a collision, you will reject the changes made anywhere but in the main node.

    Let us define the set of objects that participate in the exchange.
  4. On the Main tab, click Content.
  5. Include all the objects not related to accounting and payroll calculation into the exchange (fig. 24.3).

    Note that the NumberingPrefix constant is not included in the exchange, since its value should be unique for each database that takes part in the exchange.

    Fig. 24.3. Data exchange content
  6. On the Forms tab, in the Node field, click the Open  button and create the default node form (fig. 24.4).

    Fig. 24.4. Creating an exchange plan node form
  7. In the form controls pane, right-click the Form root item, point to Events, and click <OnCreateAtServer>.
    This creates the OnCreateAtServer event handler template. You need this handler to prohibit setting the Main attribute for the predefined node that corresponds to this infobase.
  8. Add the script shown in listing 24.4 to the handler.

    Listing 24.4. OnCreateAtServer form event handler

    Procedure OnCreateAtServer(Cancel, StandardProcessing)
        If Object.Ref = ExchangePlans.Branches.ThisNode() Then
            Items.Main.Enabled = False;
    This procedure calls the ThisNode() method of the exchange plan manager, which returns a reference to the exchange plan node that corresponds to the current infobase.
  9. Create a default exchange plan list form.
    You need this form to define some operations related to registering a new exchange node in this form.
    The main goal of these operations is generating all the change registration records for all configuration objects included in the exchange plan during the registration of a new exchange node. This basically serves as initial synchronization of the exchange node with all the exchange data.
  10. On the Commands tab, create a command named WriteChanges.
  11. In the property palette that is opened, in the Action field, click the Open  button.
  12. In the dialog box that propmts you to select handler type, click Create on client and a procedure on server (no context).
    This creates two procedures in the form module: a client WriteChanges() procedure and a server out-of-context WriteChangesAtServer procedure, which is called from the client procedure.

    As you already know, out-of-context server procedures are executed much faster than those having a context because they do not require passing the entire form context from the client to the server.

    You need to pass a reference to the ExchangePlan.Branches object as a parameter of the WriteChangesAtServer procedure. You can do it using the CurrentRow property of the List table (the table uses a dynamic list of nodes of the Branches exchange plan as its data source).
  13. Update the module text as shown in listing 24.5.

    Listing 24.5. WriteChanges() command event handler

    Procedure WriteChangesAtServer(Node)
        // Insert handler contents.
    Procedure WriteChanges(Command)
  14. Add the script shown in listing 24.6 to the WriteChangesAtServer() procedure.

    Listing 24.6. WriteChangesAtServer() procedure

        Procedure WriteChangesAtServer(Node)
        // Writing all data changes for a node
    This procedure utilizes the change registration feature by calling the RecordChanges() method of the exchange plan manager.

    A reference to the current exchange plan node (Branches) is passed to this method.

    The procedure execution creates change registration records in the infobase. These records include the changes that will be sent to the new infobase for each object included in the exchange plan content.
  15. Click the Form tab and drag the WriteChanges command from the Commands tab to the form command bar (fig. 24.5).

    Fig. 24.5. Exchange plan list form editor

    Note that the command name in the tree of form items does not exactly match the actual command name. The platform added the "Form" prefix to it, and the button linked to the command also has this name. You will use this name to access the button from 1C:Enterprise script (see listing 24.8).

    Also note that the button should only be available if the current node is not a predefined node for this infobase because otherwise it is impossible to record changes.

    To ensure such button behavior, let us create a function in the list form module that is executed on the server and returns True when the node passed to the function is a predefined one.
  16. Add the function shown in listing 24.7 to the list form module.

    Listing 24.7. PredefinedNode() function

    Function PredefinedNode(Node)
        Return Node = ExchangePlans.Branches.ThisNode();
  17. In the form controls pane, right-click the List item, open its property palette, and create the OnActivateRow event handler that is executed on the client.
  18. Populate the event handler as shown in listing 24.8.

    Listing 24.8. OnActivateRow() event handler of a list form item

    Procedure ListOnActivateRow(Item)
        If PredefinedNode(Item.CurrentRow) Then
            Items.FormWriteChanges.Enabled = False;
            Items.FormWriteChanges.Enabled = True;
    This procedure sets the availability of the WriteChanges button based on the return value of the PredefinedNode() function, which is in turn based on the reference to the current node (Item.CurrentRow) passed to the function.

    This completes the exchange plan creation and now you can proceed to the creation of data exchange procedures.
Next page: Creating data exchange procedures
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.