Forum Discussion

bgurling's avatar
14 years ago

Calling script functions from KeywordTest

Hey Guys,



Trying to do something that I think should be possible but perhaps not - still a bit new to TestComplete.



I've created a script function called Random_Invoice_Number() that connects to my database, uses a random PK to pull a value out of the database, and returns that value, see below.



My question is this - can I call this function in a keyword test in order to  retrieve the return value and use it within my keyword test? What type of reference would I use, I've tried a few different things and I keep getting an object expected failure. I have been able to use this function in other scripts by using a unit reference like this: //USEUNIT Database_Calls however, I just cannot figure out how to get my keyword test to call the Random_Invoice_Number() function and use its return value. Sorry if this is a simple solution, been digging through help files to no avail. Thanks!



Script:

function Random_Invoice_Number()

{

var ran_unrounded=Math.random()*2359;

var ran_number=Math.floor(ran_unrounded);

var invoice_number

var Qry

Qry = ADO["CreateADOQuery"]();

Qry["ConnectionString"]="Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=VP92027;Data Source=calypso\\sqlserver2005se;User ID=USER_ID;Password=PASS;";

Qry["SQL"]="SELECT invoice_number FROM In_StageA where invoice_id = " + ran_number;

Qry["Open"]();

Qry["First"]();

invoice_number=aqConvert["VarToStr"](Qry["FieldByName"]("invoice_number")["Value"]);

return invoice_number;

}