shekarls Absent Member.
Absent Member.
468 views

QC 11 - Getting Max Value from a field and using it in script Editor

HI All,

             I want to write a logic to get a Maximum value from the User defined field and always add 1 to it.

I Tried something like below, it doesnt work, let me know if there is any better way to do it without querying database to get the Maximum value.

 

TS_USER_07 is a user defined field under TEST PLAN Tab . It contains numbers, so i  have to retrieve the max number from this field.

 

Based on input from other threads, i tried putting something like below..

 

Sub getLatestValue
On Error Resume Next


dim com

dim rec
dim td

set td = TDConnection
set com = td.Command

 

'Trying to get Maxium Value from Database view Column - is this the way to do it.

 

com.CommandText = "select MAX(TS_USER_07) from dbo.V_Regression"    

 

set rec = com.Execute
rec.First

 

 ' To Add 1 to the Max value

newValue = rec.First + 1 

 

set com = nothing
set rec = nothing
set td = nothing

 

End Sub

 

Corrections and new suggestions are welcome.....

Tags (2)
0 Likes
4 Replies
Absent Member.. Trudy Claspill Absent Member..
Absent Member..

Re: QC 11 - Getting Max Value from a field and using it in script Editor

When you say it doesn't work, how do you know it doesn't work? Did you get an error message? Have you tried adding message boxes to display the data you are getting?

Often using the command "On Error Resume Next" will obscure any errors that are raised. With that command in the code, if an error is raised the interpreter won't show you the error, but will instead move on to try to execute the next line. Try removing that command and then see if an error message surfaces.
[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
0 Likes
ameyjo Outstanding Contributor.
Outstanding Contributor.

Re: QC 11 - Getting Max Value from a field and using it in script Editor

Remove the ON ERROR tags to troubleshoot, if not you will not get any error message about your code.

 

Regards

"HP Support
If you find this or any post resolves your issue, please be sure to mark it as an accepted solution"
0 Likes
Highlighted
shekarls Absent Member.
Absent Member.

Re: QC 11 - Getting Max Value from a field and using it in script Editor

Sub CurrentValue

Msgbox " Into CurrentValue Function....."

 

dim com
dim rec
dim td

set td = TDConnection
set com = td.Command
com.CommandText = "select MAX(TS_USER_07) from dbo.V_RegressionGolden"
set rec = com.Execute
rec.First
Msgbox rec.First

 

set com = nothing
set rec = nothing
set td = nothing

End Sub

 

HI,

        I removed On Error Resume Next, as discussed in this forum, how do i make sure whether its connecting to DB correctly and executing the query.

I am getting first alert(Msgbox " Into CurrentValue Function....."), but after that i am trying to print the output of the query and its coming up as blank(Msgbox rec.First ).....

 

Can i connect to Database view instead of real tables, I am not that much sure how to go about it ....

0 Likes
ameyjo Outstanding Contributor.
Outstanding Contributor.

Re: QC 11 - Getting Max Value from a field and using it in script Editor

Hi

 

This is a small sample , replace the BG_BUG_ID and BUG  by the field , Table you need in.

 

Sub Bug_MoveTo


set td = TDConnection
set com = td.command
com.CommandText = "select max( BG_BUG_ID) from BUG "
set rec = com.Execute
msgbox  rec.FieldValue(0)
set com = nothing
set rec = nothing
set td = nothing

 

End Sub

"HP Support
If you find this or any post resolves your issue, please be sure to mark it as an accepted solution"
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.