Calling script functions from KeywordTest
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2010
02:11 AM
06-07-2010
02:11 AM
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;
}
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;
}
1 REPLY 1
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2010
06:09 PM
06-07-2010
06:09 PM
Hi Bill,
You can use the Run Script Routine operation to execute a script function and the Last Operation Result value to retrieve the returned value. Please see the "Run Script Routine Operation" and"Checking Operation Result" articles for more information.
Best regards,
Alexey
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
