我试图在表单load()上的组合框中列出QC11项目和域名,但是我得到了错误对象,我正在使用的代码:
Dim tdc As New TDAPIOLELib.TDConnection
Dim projectList As Customization
Dim Project As Customization
Dim Domain As Customization
Set tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx "https://xyz/omu"
For Each Domain In TheTDConnection.DomainsList
Set projectList = tdc.GetAllVisibleProjectDescriptors
For Each Project In projectList
ComboBox1.AddItem (Project.Name)
ComboBox2.AddItem (Project.DomainName)
Next Project
Next Domain
答案 0 :(得分:0)
如果那是您正在使用的代码,那么一开始这一行可能会产生错误:
For Each Domain In TheTDConnection.DomainsList
根据你的其余代码“TheTDConnection”应为“tdc”:
For Each Domain In tdc.DomainsList
哦,要做到这一点,你几乎肯定应该首先通过调用 tdc.Login ... 登录,而不是仅仅连接到服务器。
在相关说明中,不推荐使用 DomainsList 属性。我认为您可以遍历 GetAllVisibleProjectDescriptors 返回的ProjectDescriptor对象列表,因为它涵盖了当前登录用户可以访问的所有域下的所有项目。
编辑:这是基于原始问题的完整解决方案。这是经过测试的代码,它将遍历提供的用户可以访问的域/项目。这假设您已安装QC / ALM Connectivity插件(必需)。
如果您在64位计算机上运行此VBScript,则需要使用32位版本的wscript.exe运行它:C:\Windows\SysWOW64\wscript.exe "c:\somewhere\myscript.vbs"
msgbox "Creating connection object"
Dim tdc
Set tdc = CreateObject("TDApiOle80.TDConnection")
msgbox "Connecting to QC/ALM"
tdc.InitConnectionEx "http://<yourServer>/qcbin/"
msgbox "Logging in"
tdc.Login "<username>", "<password>"
Dim projDesc
msgbox "Getting project descriptors"
Set projectDescriptors = tdc.GetAllVisibleProjectDescriptors
For Each desc In projectDescriptors
msgbox desc.DomainName & "\" & desc.Name
Next
msgbox "Logging out"
tdc.Logout
msgbox "Disconnecting"
tdc.Disconnect
msgbox "Releasing connection"
tdc.ReleaseConnection
编辑2:
如果要将生成的XML从sa.GetAllDomains解析为服务器上所有域\项目项的列表,可以执行此操作(这是VBScript,因为原始问题&amp; tag仍然提及它,并且已经过测试):
Set objDoc = CreateObject("MSXML.DOMDocument")
objDoc.Load "C:\yourXmlFile.xml"
Set objRoot = objDoc.documentElement
For Each domain in objRoot.selectNodes("TDXItem")
For Each project in domain.selectNodes("PROJECTS_LIST/TDXItem")
msgbox domain.selectSingleNode("DOMAIN_NAME").text & "\" & project.selectSingleNode("PROJECT_NAME").text
Next
Next