Quantcast
Viewing all articles
Browse latest Browse all 14708

Re: re-point a customisation field to a new list

Well it appears nobody has an answer to this one so if anyone stumbles on this looking for an answer this is how I did it...

 

 

Attribute VB_Name = "reload_target_applications_list"
Option Explicit
Dim objQCConnection As TDConnection
Dim objReqFactory As ReqFactory
Dim cust As Customization
Dim custFields As CustomizationFields
Dim aCustField As CustomizationField
Dim custLists As CustomizationLists
Dim aCustList As CustomizationList
Dim listName, cnt%
Dim listroot
Dim Node As CustomizationListNode
Dim victim As CustomizationListNode
Dim msg As String
Dim sSql As String
Dim SQLResults As Recordset

Dim iRecord

Dim newRecName
Dim newRecRsaid

Dim newRecord


Dim oCommand As Command

Sub main()
    Set objQCConnection = CreateObject("TDApiOle80.TDConnection")
    objQCConnection.InitConnectionEx "http://lnxpdb06:9080/qcbin/"
    objQCConnection.Login "me", "mypass"
    objQCConnection.Connect "mydomain", "myproject"
'Get the customization object and CustomizationFields
    'objQCConnection is the global objQCConnectiononnection object.
    Set cust = objQCConnection.Customization
    Set custFields = cust.Fields
'Walk through the fields of the bug table and output
' the some properties of the fields that are linked
' to custom lists.
    For Each aCustField In custFields.Fields("REQ")
    ' this is where we set the target field we are going to change the list for
        If aCustField.ColumnName = "RQ_USER_57" Then
                Set aCustList = aCustField.List
                Set Node = aCustList.rootnode
                MsgBox ("Current list in use is " & aCustList.Name & " with " & Node.ChildrenCount & " entries.")
                For Each victim In Node.Children
                    Node.RemoveChild (victim.Name)
                    'MsgBox victim.Name
                Next
        End If
    Next
    cust.Commit
    'we have found the list and killed it now we have to rebuild it
   
    'Create the tdc Command Object
    Set oCommand = objQCConnection.Command
    'Build the query
    sSql = "SELECT REQ.RQ_REQ_NAME as NAME, RQ_USER_56 as RSAID from REQ WHERE RQ_FATHER_ID = 17545 AND REQ.RQ_USER_21 = 'IS'"
    'Set the SQL command to the Test Coverage query
    oCommand.CommandText = sSql
    'Execute the query and store in the SQLResults resultset
    Set SQLResults = oCommand.Execute
    For iRecord = 1 To SQLResults.RecordCount
        newRecName = SQLResults.FieldValue("NAME")
        newRecRsaid = SQLResults.FieldValue("ID")
        newRecord = newRecName & " - ID " & newRecId
        Node.AddChild (newRecord)
    SQLResults.Next
    cust.Commit
    Next
   
MsgBox ("New list in use is " & aCustList.Name & " with " & Node.ChildrenCount & " entries.")

MsgBox ("Disconnecting")
disconnect
End Sub

 

Sub disconnect()
   objQCConnection.disconnect
   objQCConnection.ReleaseConnection
End Sub

Sub formatcells()
    Cells.Select
    Selection.NumberFormat = "@"
End Sub

 

 

So basically we iterate through the custom fields associated with the requirements object looking for the one I want, which is field 57, then having found it we identify the list, get the rootnode of the list and remove all the children.

 

Having done this I run some SQL to get the new list contents and then iterate through that adding the items onto the newly blanked list. Some messageboxes let me know how I am getting on.

 

It's a bit clunky and I really wanted to simply point the field to a new list but there you go.


 


Viewing all articles
Browse latest Browse all 14708

Trending Articles