Updating respnsible tester in testinstance based on TargetCycle and UD Field 'Team'

Dear All,

The below script updates the Responsible tester based on the Targetcycle selected and Team value populated.

The responsible tester value is fed from excel against the Targetcycle and Team.

This works for the selected testinstance but not the unselected testinstances.

But to update the responsible tester for the testinstances in the testset, we are looping through all the testinstances which is not working.

Your support here will be appreciated.

Sub InitializeCache()
On Error Resume Next
Set cachedResponsibleTesters = CreateObject("Scripting.Dictionary")
Dim excelApp, excelWorkbook, excelSheet, row, targetCycle, team, responsibleTester,combinedKey

Set excelApp = CreateObject("Excel.Application")
Set excelWorkbook = excelApp.Workbooks.Open("C:\ALM\ResponsibleTester.xlsx") ' Update with the correct path
Set excelSheet = excelWorkbook.Sheets(1)

' Assuming the data starts from row 2
row = 2
Do While excelSheet.Cells(row, 1).Value <> ""
targetCycle = excelSheet.Cells(row, 1).Value
team = excelSheet.Cells(row, 2).Value
responsibleTester = excelSheet.Cells(row, 3).Value

'Msgbox "targetCycle from excel:" & targetCycle
'Msgbox "team from excel:" & team
'Msgbox "responsibleTester from excel:" & responsibleTester

' Store in the cache using a combined key
cachedResponsibleTesters(targetCycle & "-" & team) = responsibleTester
combinedKey = cachedResponsibleTesters(targetCycle & "-" & team)
'Msgbox "combined key:" & combinedKey
row = row + 1
Loop

excelWorkbook.Close False
excelApp.Quit
cacheInitialized = True
'MsgBox "Cache initialized successfully."
On Error GoTo 0
End Sub

Function GetResponsibleTesterFromCache(targetCycle, team)
Dim key
key = targetCycle & "-" & team
'MsgBox "key:" & key
If cachedResponsibleTesters.Exists(key) Then
GetResponsibleTesterFromCache = cachedResponsibleTesters(key)
'MsgBox "GetResponsibleTesterFromCache:" & GetResponsibleTesterFromCache
Else
GetResponsibleTesterFromCache = ""
'MsgBox "GetResponsibleTesterFromCache:" & GetResponsibleTesterFromCache
End If
End Function

Sub AssignResponsibleTesterToAllTestInstances()
On Error Resume Next
If Not cacheInitialized Then
InitializeCache
End If

' Retrieve the current test set
Dim testSet, testInstanceFactory, testInstances, i, targetCycle, team, responsibleTester
Set testSet = TDConnection.TestSetFactory.Item(TestSet_Fields("CY_CYCLE_ID").Value)

If testSet Is Nothing Then
MsgBox "No active Test Set found. Ensure the script is executed in the Test Lab context."
Exit Sub
End If

' Get all test instances in the test set
Set testInstanceFactory = testSet.TSTestFactory
Set testInstances = testInstanceFactory.NewList("")

' Iterate and process each test instance
For i = 1 To testInstances.Count ' ALM uses 1-based indexing
Dim currentTestInstance
Set currentTestInstance = testInstances.Item(i)
MsgBox " currentTestInstance: " & currentTestInstance

' Retrieve target cycle and team for the current test instance
targetCycle = Trim(currentTestInstance.Field("TC_ASSIGN_RCYC").Value.Name)
team = Trim(currentTestInstance.Field("TC_USER_TEMPLATE_03").Value)

' Fetch the responsible tester from the cache
responsibleTester = GetResponsibleTesterFromCache(targetCycle, team)

' Assign the responsible tester if found
If Not IsNull(responsibleTester) And responsibleTester <> "" Then
currentTestInstance.Field("TC_TESTER_NAME").Value = responsibleTester
currentTestInstance.Post ' Commit changes to the database
End If
Next
On Error GoTo 0
End Sub

Thank You!!!