How to set a range for a User Defined Field in QC

  • Questions
  • How to set a range for a User Defined Field in QC
Tags:
Question ID: 104777
0
0

I wish to limit a user defined field in the defect module to a range of characters. For example, the field must be at least X characters long but cannot exceed Y characters in total length. When playing with strings and lists in project customization, not seeing the exact outcome I wish. Is there an easier way?

Please help, as my genie only gave me 3 wishes, and I’ve been told I can’t just wish for more wishes.

Marked as spam
Posted by (Questions: 104, Answers: 0)
Asked on December 31, 2012 3:48 pm
14 views
Answers (1)
2
Private answer

I believe the following code might be what you have in mind.

Below is an older example of code from HP for some custom workflow code. The code is pretty simple so should be too hard at all to adapt to your setup.

The below features BG_USER_03 for the UDF in question, but you can obviously put in whatever UDF you are working with.

In the Bug_FieldChange subroutine, it checks whether the user types in between 15-30 characters. If not, it returns an error message and resets the value to what it originally was. The LastValue function is a utility function that returns the original value of the field before any changes were made.

Example:

Sub Bug_New
End Sub

Sub Bug_FieldChange (FieldName)
' Check the length of the string that the user types in BG_USER_03.
' If the length is not between 15 to 30 characters, return an error message and
' switch back the value to what it originally was.

if FieldName = ''BG_USER_03'' and (Len(Fields(''BG_USER_03'').Value)<15 or Len(Fields(''BG_USER_03'').Value)>30) then

MsgBox ''This field should be between 15 to 30 characters long!''
Fields(''BG_USER_03'').Value = LastValue(''BG_USER_03'')
end if

End Sub

Sub Bug_MoveTo
End Sub

Function Bug_CanPost
End Function

Function LastValue(FieldName)

'This function returns the value of the field before the user changes it.
'FieldName - name of field you are looking for

dim com
dim rec
dim td

'If the bug is new then the previous value is Null

if fields(''BG_BUG_ID'').IsNull then LastValue =''''
exit function
end if

set td = TDConnection
set com = td.Command
com.CommandText = ''select '' & FieldName & '' from BUG where BG_BUG_ID='' &Fields(''BG_BUG_ID'').Value

set rec = com.Execute
rec.First
LastValue = rec.FieldValue(Cstr(FieldName))

set com = nothing
set rec = nothing

End Function

Marked as spam
Posted by (Questions: 1, Answers: 116)
Answered on December 31, 2012 4:04 pm
That looks very useful. Thank you!
( at December 31, 2012 4:31 pm)