Toad World® Forums

$BFSetVar / $BFSetVarRtn


Does anyone have any examples of how to use the above script variables or any links to references on the subject?



There is some documentation on the two bfscript functions in the help files, but here is an example how it has can be used;

BFSetVarRtn - Sets the specified variable to the value and returns with that value

Say you have a SQL that updates a table with a persons first and last name and a unique identifier with is made up of their name. So you would have the SQL;

INSERT INTO CUSTOMERS (FirstName, LastName, Address, CustomerID) values (‘Joe’, ‘Smith’, ‘Address 1’, ‘Joe-Smith-00001’)

If you wanted to use BFScripts to randomize these values you could write the following;

INSERT INTO CUSTOMERS (FirstName, LastName, CustomerID) values (’$BFSetVarRtn(‘CustomerFirstName’, $BFFirstName())’, ‘$BFSetVarRtn(‘CustomerLastName’,$BFLastName())’, ‘$BFGetVar(‘CustomerFirstName’)-$BFGetVar(‘CustomerLastName’)-00001’)

As can be seen we are using BFSetVarRtn and BFGetVar to save the generated values for the first and last names and use them later in the query.

BFSetVar - Sets the specified variable to the value, but returns empty

Where I have seen this used is when you have a large user scenario with many different values that you would like to generate and save. Instead of doing the setting of the variables when they are used, which works, it is sometimes easier to set all the values at the first SQL statement of the user scenario so that you know where they all are.

So let’s take the above example and say that CustomerFirstName, CustomerLastName, and CustomerZip are used in a large user scenario which has a first SQL statement something like;

SELECT FirstName, LastName, CustomerID from CUSTOMERS

you could set all the variables in this point, so the SQL statement would look like this;

$BFSetVar(‘CustomerFirstName’, $BFFirstName())
SELECT FirstName, LastName, CustomerID from CUSTOMERS

Since all the BFSetVar functions return an empty string, the above SQL evaluates to just the select statement.

I know these examples are very complicated, but I hope they help


Thanks for that reply.

I’ll go away and try and create some scenarios that use these variables.





Query 1 executes fine, but query 2 fails with a ‘SCRIPT ERROR’.

Can anyone help?


I’ve created a simple Custom Load Scenario with two Query’s:

Query 1

$BFSetVar(‘Invcode’, $BFRandRange(1,735166))WHERE INVCODE = $BFGetVar(‘Invcode’)

Query 2


To use the setting of variables in the first query you will need to be running all the queries inside a user scenario so that you can guarantee that the statement with all the setting of variables are executed first. A user scenario tells BMF to run all of it’s statements in the order as shown. So your test would look like;

Custom Load Scenario
User Scenario

Query 1
Query 2
Query n

If you run the queries inside a mix test without being inside a user scenario, the test will randomly pick for all virtual users what statements to run next. So Query 1 may not be the first statement that a particular virtual user will execute and thus you will get an error running Query 2. Now you will get errors until the virtual user executes Query 1 and from then on Query 2 will execute without error.


Thanks for the advice, I have now got this working.