Geethika,
My intention for suggesting to create user field is for persistent storage, creating files is a bit clumsy. However, it is not possible to create user fields for test set folders (since it does not display in Project Entities) and so i have used CommonSettings object to store this information.
1. In Script Editor -> Toolbar Button Editor, created two actions TestLab_Lock and TestLab_UnLock
2. Insert these lines in ActionCanExecute function to intercept our custom actions.
If ActionName = "TestLab_Lock" Then
TLLock(TSFFolderId)
ElseIf ActionName = "TestLab_Unlock" Then
TLUnLock(TSFFolderId)
End If
3. Define new Global variable and insert following line in TestSetFolder_MoveTo Function.
TSFFolderId = TestSetFolder_Fields("CF_ITEM_ID").Value
4. Verify whether Folder is locked or not within TestSetFolder_CanDelete function
Function TestSetFolder_CanDelete(Entity) On Error Resume Next TestSetFolder_CanDelete = False If IsTLLocked(Entity.NodeID) = False Then If IsTLParentsLocked(Entity.NodeID) = False Then If IsTLChildsLocked(Entity.NodeID) = False Then TestSetFolder_CanDelete = True Else Msgbox "SubNodes locked" End If Else Msgbox "Parent Folders locked" End If Else Msgbox "Folder is locked" End If On Error GoTo 0 End Function
5. Following function helps in storing/retrieving/verifying/removing the list of locked test set folders in common setting. These functions are minimalistic, like i'm checking only 1st level of subnodes are locked or not. These functions can be used only for locking test set folder and not test sets, users can still delete test sets. But this should get you started.
Function IsTLLocked(FolderId) On Error GoTo 0 IsTLLocked = False Set cset = TDConnection.CommonSettings cset.Open("TestLabFolder") fldrset = cset.value("LockedFolders") fldrs = split(fldrset,",") For Each fldr In fldrs if CInt(fldr) = FolderId Then IsTLLocked = True End If Next cset.Close End Function Function IsTLParentsLocked(FolderId) IsTLParentsLocked = False Set TSTree = TDConnection.TestSetTreeManager Set TSFldr = TSTree.NodeById(FolderId) FatherId = TSFldr.FatherID do while FatherId <> 0 If FatherId <= 0 Then Exit Function End If If IsTLLocked(FatherId) = True Then IsTLParentsLocked = True Exit Function End If Set TSFldr = TSTree.NodeById(FatherId) FatherId = TSFldr.FatherID loop End Function Function IsTLChildsLocked(FolderId) IsTLChildsLocked = False Set TSTree = TDConnection.TestSetTreeManager Set TSFldr = TSTree.NodeById(FolderId) Set TSChilds = TSFldr.SubNodes For Each TSChild In TSChilds If IsTLLocked(TSChild.NodeID) = True Then IsTLChildsLocked = True Exit Function End If Next End Function Function TLLock(FolderId) On Error GoTo 0 TLLock = False Set cset = TDConnection.CommonSettings cset.Open("TestLabFolder") fldrset = cset.value("LockedFolders") fldrs = split(fldrset,",") For Each fldr In fldrs if CInt(fldr) = FolderId Then TLLock = True End If Next If TLLock = False Then If Len(fldrset) > 0 Then fldrset = fldrset & "," & FolderId else fldrset = FolderId End If cset.value("LockedFolders") = fldrset cset.Post TLLock = True End If cset.Close End Function Function TLUnLock(FolderId) On Error GoTo 0 TLUnLock = True Set cset = TDConnection.CommonSettings cset.Open("TestLabFolder") fldrset = cset.value("LockedFolders") fldrs = split(fldrset,",") lckfldrs = "" For Each fldr In fldrs if CInt(fldr) = FolderId Then TLUnLock = False else lckfldrs = lckfldrs & fldr & "," End If Next If TLUnLock = False Then If Len(lckfldrs) > 0 then cset.value("LockedFolders") = Mid(lckfldrs,1,Len(lckfldrs)-1) Else cset.value("LockedFolders") = "" End If cset.Post TLUnlock = True End If cset.Close End Function