I have figured out how to do it automatically:
Add this code to the 'ActionCanExecute' function:
If Actionname = ''act_run'' Then
Set us = TDConnection.UserSettings
us.Open ''MySettings''
us.Value(''LastTestInstanceID'') = TestSetTest_Fields(''TC_TESTCYCL_ID'').Value
us.Close
us.Post
Set us = Nothing
End If
If Actionname = ''act_end_run'' or ActionName = ''RfrshAct'' Then
Set us = TDConnection.UserSettings
us.Open ''MySettings''
us.DeleteValue ''LastTestInstanceID''
us.Close
End If
Add this code to the Bug_AfterPost function:
Set us = TDConnection.UserSettings
us.Open ''MySettings''
lTestInstanceId = us.Value(''LastTestInstanceID'')
BugID = Bug_Fields(''BG_BUG_ID'').Value
us.Close
if lTestInstanceId <> '''' then
Set td = TDConnection
Set objTCtestFac = td.TSTestFactory
Set ojbTCtest = objTCtestFac.Item(lTestInstanceId)
Set objBugLinkFac = ojbTCtest.BugLinkFactory
Set objLink = objBugLinkFac.AddItem(BugID)
objLink.LinkType = ''Related''
objLink.Post
End If
Set us = Nothing
This will automatically link any defect you raise while running a test to the test INSTANCE.
Note that this may skew defect reports as it will say there are two linkages, one to the instance and another to the step/run.