Public Sub AddTrack(oRecord As IBBDataObject)



   Dim oConst As CRecord

   Dim oTrack As CTrack

   Dim oTracks As CTracks

   Dim oTrackAction As CTrackAction

   Dim oAction As cAction

   Dim lTrackActionID As Long

                           

   Set oTracks = New CTracks

   With oTracks

       .Init REApplication.SessionContext

   

       'locate the "Boss Track" track

       For Each oTrack In oTracks

       

           If UCase$(oTrack.Fields(Track_fld_NAME)) = "BOSS TRACK" Then

           

               'look for the TrackAction template upon which the constituent action

               'should be based.  Sounds like you want the first 'action' in the Track

               'template, but you could also use whatever criteria you want here to determine

               'which template to start with.  To get the ID of the first template in the

               'TrackActions collection, you can simply use:

               '

               '   lTrackActionID = Val(oTrackAction.TrackActions.Item(1).Fields(TrackAction_fld_ID))

               '

               'but it's probably more correct to locate the TrackAction using whatever

               'criteria is important (like action type, or whatever).  For now, I'll just

               'check the sequence field to illustrate that you may want to use criteria

               'here rather than the first item in the collection.

               For Each oTrackAction In oTrack.TrackActions

                   If Val(oTrackAction.Fields(TrackAction_fld_SEQUENCE)) = 1 Then

                       lTrackActionID = Val(oTrackAction.Fields(TrackAction_fld_ID))

                       Exit For

                   End If

               Next oTrackAction

               Set oTrackAction = Nothing

           End If

           

           oTrack.CloseDown

           If lTrackActionID > 0 Then Exit For

       Next oTrack

       Set oTrack = Nothing

   

       .CloseDown

   End With

   Set oTracks = Nothing

       

   'create the action based on the TrackAction template we found

   Set oAction = New cAction

   With oAction

       .Init REApplication.SessionContext

       

       'Note that the oConst variable isn't really needed, you could oRecord which is

       'an IBBDataObject, so it also has a Fields collection.  The only thing you'd give

       'up by doing so is the nice intellisense enum list that we expose off of the CRecord

       'Fields property.

       Set oConst = oRecord

       .Fields(ACTION_fld_RECORDS_ID) = Val(oConst.Fields(RECORDS_fld_ID))

       Set oConst = Nothing

       

       'indicate that this action is based on the located TrackAction template in the

       '"Boss Track" action track.  This allows you to view the template information

       'from the action record itself, and will also facilitate creating subsequent

       'actions from the track whenever the conditions defined on the template are met

       'for generating the next action (for example, when this action is marked as Closed,

       'the next action in the track would be generated).

       .Fields(ACTION_fld_TRACKACTION_ID) = lTrackActionID

       'Insert default values for the first action here

       .Fields(ACTION_fld_TYPE) = "Birthday"

       

       .Save

       .CloseDown

   End With

   Set oAction = Nothing

   

End Sub

Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Microsoft Visual Basic and the tools used to create and debug procedures. Our Customer Support can help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality. If you are interested in learning more about the VBA and API modules, contact your account manager.