Lookup Fields in HP Quality Center - hp-quality-center

I am interfacing with Quality Centre via Open Test Architecture API.
I would like to determined the allowed values of bug Fields that are linked to a lookup table.
These are available via drop downs in the standard frontend.
Thanks
Edit: A more Detailed explanation
We have some fields which will only allow specific values to placed in them.
For example:
NextAction can be one of the following { "1. Specify", "2. Analysis", "3. Design" }
But I have been unable to find a way to determine these allowed values programmatically.

Using the BugFactory object you can access the fields and their attributes. This is a direct copy / paste of Visual Basic from the OTA API Reference help file. If you want more help, try providing a more focused question, such as what you're trying to accomplish, which fields, and which language you're trying to access with.
Public Sub CheckValidValue(Optional TableName As String = "BUG")
Dim BugFact As BugFactory
Dim BugList As list
Dim aField As TDField
Dim fieldList As list
Dim rc, ErrCode As Long
Dim aBug As Bug
Dim msg$
Dim okCnt%, noNodeCnt%, errorCnt%, unknownCnt%
Dim dataType As Long
'------------------------------------------------
' User BugFactory.Fields to get a list of TDField
' objects in the bug table.
' This example uses the BugFactory, but this can
' be done with any class that implements IBaseFactory
'tdc is the global TDConnection object.
Set BugFact = tdc.BugFactory
Set fieldList = BugFact.Fields
'------------------------------------------
' Use List.Count to check how many items.
Debug.Print: Debug.Print
Debug.Print "There are " & fieldList.Count & _
" fields in this table."
Debug.Print "----------------------------------"
'Get any bug. To look at field attributes we
' need a valid object and since this example is
' not interested in the particular values of the object,
' it doesn't matter which bug.
Set BugList = BugFact.NewList("")
Set aBug = BugList(0)
'Walk through the list
For Each aField In fieldList
With aField
'Quit when we have enough for this example
If InStr(aField.Name, "BG_USER_10") > 0 Then Exit For
' For the DataTypeString() code,
' see example "Convert data types to string"
Debug.Print .Name & ", " & .Property & ", Data type is " _
& DataTypeString(.Type)
On Error Resume Next
'----------------------------------------------------
'Use TDField.IsValidValue to confirm that a value can
'be used for a field.
' Get the correct data type and check validity of an
' arbitrary value.
' Save the error code immediately after IsValidValue call
' before another call can change the err object.
dataType = aField.Type
Select Case dataType
Case TDOLE_LONG, TDOLE_ULONG
aField.IsValidValue 5, aBug
ErrCode = err.Number
Case TDOLE_FLOAT
aField.IsValidValue 5.5, aBug
ErrCode = err.Number
Case TDOLE_STRING
aField.IsValidValue "Joe", aBug
ErrCode = err.Number
Case Else
'These will be errors:
aField.IsValidValue _
"String to non-string value", aBug
ErrCode = err.Number
End Select
'Output an error code message
If ErrCode = 0 Then 'S_OK
msg = "Valid Value"
okCnt = okCnt + 1
Else
rc = ErrCode - vbObjectError
Select Case rc
Case FIELD_E_VERIFIED
msg = "Error: Invalid value for field"
errorCnt = errorCnt + 1
Case TDOLE_NONODE
msg = "Error: Field can not be set to this value"
noNodeCnt = noNodeCnt + 1
Case Else
msg = "Unrecognized error: " & rc _
& " , HRESULT = " & ErrCode
unknownCnt = unknownCnt + 1
End Select
End If
Debug.Print vbTab & msg
'
End With 'aField
Next aField
Debug.Print "----------------------------------"
Debug.Print "Number of fields with valid value = " & okCnt
Debug.Print "Number of fields with invalid type = " & errorCnt
Debug.Print "Number of fields with invalid value= " & noNodeCnt
Debug.Print "Number of fields with unknown error = " & unknownCnt
Debug.Print "----------------------------------"
End Sub

You can do this by looking up the list from the 'Customization' object. Here's how I'd do it using ruby:
qc = WIN32OLE.new('TDApiOle80.TDConnection')
qcserver = 'http://testdirector/qcbin/'
qc.InitConnectionEx(qcserver)
qc.Login($username, $password)
qc.Connect("$domain", "$project")
customization = #qc.Customization
list = custom.Lists.List("NextAction")
node = list.RootNode
children = node.Children
children.each do |child|
puts "#{child.Name} \n"
end

Related

What is wrong with the Search Form codes?

I have a Search Form which have a sub form in it.
I keep getting Run-time error '3075': Syntax error(missing operator) in query expression '[MC_No] like '' [Customer] like '' [Date_Recorded] = #23/11/2016# AND [Product] like '*".
Can anybody identify my error? I have checked every single line. Maybe I missed out on something.
These are my codes
Private Sub Search_Click()
Dim strDatePicker As String
Dim cboMC As String
Dim strProduct As String
Dim cboCustomer As String
Dim sql As String
sql = "select * FROM 3_OEE WHERE "
If IsDate(Me.DatePicker) Then
strDatePicker = " [Date_Recorded] = #" & DateValue(Me.DatePicker) & "#"
Else
strDatePicker = " [Date_Recorded] like '*'"
End If
If IsNull(Me.MC_No) Then
cboMC = " [MC_No] like '*'"
Else
cboMC = " [MC_No] like '" & Me.MC_No & "'"
If IsNull(Me.Customer) Then
cboCustomer = " [Customer] like '*'"
Else
cboCustomer = " [Customer] = '" & Me.Customer & "'"
End If
Me.subfrmOEE.Form.RecordSource = sql (*Error highlights this code*)
Me.subfrmOEE.Form.Requery
On the line with the error, your variable sql is the same as it was when you first declared it, i.e.: "select * FROM 3_OEE WHERE ".
This is not a valid query. You need to either remove WHERE from the end of that query or append to the sql variable the rest of the query statement (in other words, add the WHERE conditions to the end of the query).

GetCurrentUserName() is causing crash in MS Access 2010

I am running Windows 7 Professional. I have an MS Access frontend to an MS Access backend. The form that opens at the start of opening the frontend causes the app to crash.
Here is the code:
Private Sub Form_Open(Cancel As Integer)
Dim strMyDir As String
Dim intPos As Integer
Dim rst As dao.Recordset
Dim strSQL As String
Dim rstWhatsNew As dao.Recordset
DoCmd.ShowToolbar "Database", acToolbarNo
DoCmd.ShowToolbar "Toolbox", acToolbarNo
DoCmd.ShowToolbar "Form View", acToolbarNo
If Application.GetOption("ShowWindowsInTaskbar") = -1 Then
Application.SetOption "ShowWindowsInTaskbar", 0
End If
If DLookup("Locked", "luLockOut") <> 0 Then
MsgBox "Database is being worked on. Please try back in a couple minutes.", vbInformation, " "
DoCmd.Quit
Else
strSQL = "Select * From tblLastLogins Where UserName = '" & GetCurrentUserName() & "'"
This is where I have traced the error to: GetCurrentUserName()
Set rst = CurrentDb.OpenRecordset(strSQL)
With rst
If Not .EOF Then
.Edit
strSQL = "Select WhatsNewID From tblWhatsNew Where DateAdded >= #" & !LastLoginDate & "#"
Set rstWhatsNew = CurrentDb.OpenRecordset(strSQL)
While Not rstWhatsNew.EOF
DoCmd.OpenForm "frmWhatsNew", , , , , acDialog, rstWhatsNew!WhatsNewID
rstWhatsNew.MoveNext
Wend
rstWhatsNew.Close
Set rstWhatsNew = Nothing
Else
.AddNew
!UserName = GetCurrentUserName()
End If
!LastLoginDate = Now()
!IsLoggedIn = -1
Me.txtLastLoginID = !LastLoginID
.Update
.Close
End With
Set rst = Nothing
DoCmd.OpenForm "frmPrivacyNote"
Debug.Print Me.txtLastLoginID
End If
I need to track the username, so if GetCurrentUserName() is outdated, what is the current syntax?
Further follow up. I could not find data on Bing for GetCurrentUserName(), for good reason. It is a function within a MOD, so I need to figure out why the MOD is not getting called, or is malfunctioning.
After further delving, I found a Referenced MDB that has another function created by one of our users that is the cause of this error.
This is currently not an issue of MS Access working incorrectly. It is an issue with user created code.
GetCurrentUserName() is not defined by Access, so you should have looked at (and posted) its code.
If you are looking for the Windows user name, use this function:
Public Function GetUserName() As String
' GetUserName = Environ("USERNAME")
' Environ("USERNAME") is easily spoofed, see comment by HansUp
GetUserName = CreateObject("WScript.Network").UserName
End Function
Source
The link below would suggest that
CurrentUser()
is the function
CurrentUser()
Andre, thank you very much for the insight! I found this link:
http://www.codeproject.com/Articles/1422/Getting-User-Information-Using-WSH-and-VBScript
Dim objNet
On Error Resume Next
'In case we fail to create object then display our custom error
Set objNet = CreateObject("WScript.NetWork")
If Err.Number <> 0 Then 'If error occured then display notice
MsgBox "Don't be Shy." & vbCRLF &_
"Do not press ""No"" If your browser warns you."
Document.Location = "UserInfo.html"
'Place the Name of the document.
'It will display again
End If
Dim strInfo
strInfo = "User Name is " & objNet.UserName & vbCrLf & _
"Computer Name is " & objNet.ComputerName & vbCrLf & _
"Domain Name is " & objNet.UserDomain
MsgBox strInfo
Set objNet = Nothing 'Destroy the Object to free the Memory

Access adding records from one table

I have a table EmpRequirements, the fields are:
EmpRequirementsID (AutoNumber),
EmpID (from the Employees Table),
RequirementID (from the Requirement Table),
RequirementName (from the Requirement Table),
Received_OnFile (Check),
NotApplicable (Check),
DateReceived (Date),
ExpirationDate (Date)
What I want to do is have a Button (Add Requirements) that on Click will add all of the data from Requirement Table (Requirement ID, and RequirementName) for the Employee that is current on my form. If I add a Requirement I would like to be able to click the Button and it will add any and all Requirements to that employee that currently do not exist for that employee.
This would then show up in the form as a Subform datasheet where the user can then edit all of the other fields in the EmpRequirements.
I have tried to use Append and Update and to date have not come up with the answer. I wonder if this could be just an easy Macro to write.
I have tried to add the records using this statement, I have ' out the error handler, and am getting the run time error 3134 - syntax error insert into statement
Private Sub Add_Click()
' On Error GoTo Err_Add_Click
Dim strSQL1 As String
strSQL1 = "INSERT IGNORE INTO [EmpRequirements]( [EmpID], [RequirementID], [RequirementName] )" & _
"SELECT DISTINCT [Employees].[EmpID], [Requirement].[RequirementID], [Requirement].[RequirementName]" & _
"FROM [Employees], [Requirement] " & _
"WHERE (((Employees.EmpID)=[Forms]![Employee Details]![EmpID]));"
DoCmd.RunSQL strSQL1
[Forms]![Employee Details].Refresh 'Refresh after update EmpRequirements Subform
'Exit_Add_Click: ' Label to resume after error.
' Exit Sub ' Exit before error handler.
'Err_Add_Click: ' Label to jump to on error.
' MsgBox Err.Number & Err.Description ' Place error handling here.
' Resume Exit_Add_Click ' Pick up again and quit.
End Sub
Will this work and can you help with the error?
Here is the answer I came up with
Private Sub Add_Click()
On Error GoTo errHandler
Dim strSQL1 As String
DoCmd.SetWarnings False
strSQL1 = "INSERT INTO EmpRequirements ( EmpID, RequirementID, RequirementName ) " & _
"SELECT SQ1.EmpID, SQ1.RequirementID, SQ1.RequirementName " & _
"FROM (SELECT Employees.EmpID, Requirement.RequirementID, Requirement.RequirementName " & _
"FROM Employees, Requirement WHERE (((Employees.EmpID)=[Forms]![Employee Details]![EmpID]))) " & _
"AS SQ1 LEFT JOIN EmpRequirements ON (SQ1.EmpID=EmpRequirements.EmpID) " & _
"AND (SQ1.RequirementID= EmpRequirements.RequirementID) " & _
"WHERE EmpRequirements.RequirementID IS NULL;"
DoCmd.RunSQL strSQL1
DoCmd.SetWarnings True
[Forms]![Employee Details].Refresh 'Refresh after update EmpRequirements Subform
Exit Sub ' Exit before error handler.
errHandler: ' Label to jump to on error.
MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
VBE.ActiveCodePane.CodeModule, vbOKOnly, "Error"
End Sub
Thanks all

How to include multiple messages in one MsgBox

I want to include multiple messages in one MsgBox using \n. I need to remove this string when the MsgBox is shown.
This is my code.
Dim Msg As String = ""
Dim EmployeeFirstName As String
Dim EmployeeLastName As String
EmployeeFirstName = txtFirstName.Text.Trim
EmployeeLastName = txtLastName.Text.Trim
If EmployeeFirstName = "" Then
Msg = "Please enter First Name!"
Msg += "/n"
End If
If EmployeeLastName = "" Then
Msg += "Please enter Last Name!"
Msg += "/n"
End If
If ddlGender.SelectedItem.Value = -1 Then
Msg += "Plrase Select department"
Msg += "/n"
End If
MsgBox(Msg)
StringBuilder is usually a good choice when you need to build a string dynamically. It often performs better, and generally makes for cleaner, more maintainable code than doing a bunch of string concatenation.
Dim msgBuilder As New StringBuilder()
'...
If EmployeeFirstName = "" Then
msgBuilder.AppendLine("Please enter First Name!")
End If
'And so forth
MsgBox(msgBuilder.ToString())
But, as Matt Wilko points out, if this is ASP.NET, you don't want to use MsgBox at all.
Like this ...
Msg = "Please enter First Name!" & vbCrlf
Msg &= "Please enter Last Name!" & vbCrlf
Msg &= "Please Select department"

Storing a Dictionary to a Session

I created this function but it seems to give me a problem. I want to store a dictionary into an Session variable so I can access the dictionary throughout the website. I keep getting the error Object required: DictionaryObject or it will say This key already exist in the dictionary. Can someone please tell me what I am doing wrong?
I did look storing dictionary in session at this posting but didn't really fit what I am trying to do!
Function LoadPermissions()
Dim SQLString
SQLString ="SELECT datafields here... FROM " & TBL_employees_permissions & " AS p WHERE p.eid = '" & Clng(12) & "';"
If IsObject(Session("dicPermissions")) = True Then
Set dicPermissions = Session("dicPermissions")
Else
Set dicPermissions = Server.CreateObject("Scripting.Dictionary")
End If
db_conn conn, rs '
Set myRS = conn.Execute (SQLString)
For each item in myRS.Fields
If IsObject(Session("dicPermissions")) = True AND DictionaryObject.Exists(Trim(item.Name)) = False Then
dicPermissions.Add Trim(item.Name), Trim(myRS(item.Name))
End If
Next
db_disconn conn, rs
Set Session("dicPermissions") = dicPermissions 'Store Dictionary to session array.
End Function
I was able to get it working and here is what I did? If anyone see anything wrong or if I need to add in any error trapping. This is load once when the user logs in.
Dim SQLString
SQLString ="SELECT Datefields here... & " AS p WHERE p.eid = '" & Clng(12) & "';"
'Create the dictionary object.
Set Session("dicPermissions") = Server.CreateObject("Scripting.Dictionary") 'Create the Dictionary object.
'sets up a connection to the database
db_conn conn, rs 'Open account table.
Set myRS = conn.Execute (SQLString) ' Uses any ADODB connection
For each item in myRS.Fields 'Create the dictionary with the field names and cell data.
'dicPermissions.Add fieldname, feild value
Session("dicPermissions").Add Trim(item.Name), Trim(myRS(item.Name))
Next
db_disconn conn, rs 'Close the database
You can access it like so:
Response.write Session("dicPermissions").Item("itemnamehere...")

Resources