Accessing Data Bank Values in Groovy Script
I have an extension tool test in my scenario that calls a Windows command file (.bat). This is a very simple command that returns the userid of the person logged into the computer. This is put into a databank that I want to pass into the Groovy script to build the file path for a PDF file the web application creates and downloads. The script does retrieve the userid and build the correct path to find the file (I only need to make sure the file is created.) The problem is that the script is throwing an error even though it works correctly.
This is the error it returns:
Error Message:
DataSource: DataHold (row 1), Logon Court Tab (row 1): No Data Source named "GetTDBUserid" found.
View Details for more information.
Additional Details:
Please verify that the Data Source is spelled correctly. Also verify that the "Use data source"
check box is selected and that the correct Data Source is selected in the Data Source combo box.
I have tried checking and unchecking the Use data source checkbox on the Tool Setting tab of the extension tool. Am I missing something?
Here is the Groovy script:
**
import com.parasoft.api.*;
import java.io.*;
public boolean verifyReport(Object input, Context context)
{
reportFilePath1 = context.getEnvironmentVariableValue("ReportFilePath1");
reportFilePath2 = context.getEnvironmentVariableValue("ReportFilePath2");
reportFullPath = reportFilePath1 + context.getValue("GetTDBUserid","TDBUserid") + reportFilePath2;
Application.showMessage("reportFullPath: " + reportFullPath);
File file = new File(reportFullPath);
if (file.length() > 0)
{
file.delete();
return true;
}
else
{
return false;
}
}**
Sorry this is so long. Thanks for any assistance!
Comments
-
Since "TDBUserid" is a data bank column name, you should pass null as the first argument to context.getValue(). Right now, you are passing "GetTDBUserid", which is making SOAtest try to find a data source with that name. If you pass null, it will just find the data bank value.
1 -
Thanks jakubiak! That worked. I actually passed in an empty string for the data source name instead of a null value and it worked just as you said.
1 -
This looks like a SOAtest question (not Selenic). For custom data bank column names, the data source name has always been "Generated Data Source" as in
context.getValue("Generated Data Source", "columnName").
I've never heard of using null for the data source working. Perhaps it is an undocumented trick.0 -
"Generated Data Source", "", and null all work as the data source name when retrieving a data bank value.
0