Adding batches

After the campaign's properties have been set, batches can be added to the campaign. Batches can be added to a campaign at anytime before or after the campaign has been added to the Campaign Manager server. However, it is desirable to add as many batches as needed to the campaign before the campaign is added to the Campaign Manager server because each new batch fires several events when added. Again, in order to reduce network traffic, batches should be added before adding the campaign to the Campaign Manager server to whatever extent possible.

Each batch in a campaign needs to have a unique batch ID. Therefore, to add a batch, the first thing is to create the batch ID. Batch IDs are normally comprised of a prefix, suffix, and some kind of counter to keep each ID unique. One method is to use the campaign's StartSequence. When a new campaign is created the StartSequence is set to 0. Each time a batch is added, the StartSequence can be incremented by one to have a running total of how many batches have been created for the campaign. Once the batch ID is created, a new batch edit object can be retrieved and added to the campaign.

The following is an example sub written in Visual Basic that shows how to correctly add a batch to a campaign.

Private Sub AddBatch(ByRef objCampaignEdit As IDVBCMCampaignEdit4)
    Dim lCounter As Long
    Dim strBatchID As String
    Dim strPrefix As String
    Dim strSuffix As String
    Dim objBatchEdit As DVBCMBatchEdit
    strPrefix = objCampaignEdit.Prefix
    strSuffix = objCampaign.Suffix
    lCounter = objCampaignEdit.StartSequence
    strBatchID = strPrefix & (format (lCounter, "00000")) & strSuffix
    Set objBatchEdit = objCampaignEdit.NewBatch(strBatchID)
    Call objCampaignEdit.AddBatch(objBatchEdit, FALSE, FALSE)
    objCampaignEdit.StartSequence = lCounter + 1
End Sub

Looping through the code above will create as many batches as desired on the campaign. The two Boolean parameters at the end of the AddBatch function indicate if the batch is a setup or cleanup batch. Each campaign is allowed one setup and one cleanup batch. If a batch is marked as a setup or a cleanup when one of that type already exists, the call will fail. Each batch created has its recipe object filled with the base recipe object of the campaign. Each batch can have its recipe object edited to a different recipe just as the campaign's recipe object was edited. This is usually the case in a setup or cleanup batch. The process is to retrieve all the new data from an executive object and the user selects from that data. The changes (user selections) are then made to the batch's recipe edit object.