DataSet scope
Having a problem with the scope for DataSet.
This is what I'm doing.
Fetching a zip from a file of zipcodes.
Passing it to the url.
Extractor pattern 1 looks for the place in the code that contains 12 months of data, and saves that portion of the page to ~@YearData@~.
Fine.
Calls "DataExtract" script "after each pattern application"
The "DataExtract" script starts with -
DataSet mydata = scrapeableFile.extractData(dataRecord.get("YearData"), "get_1_month");
to extract each month from the captured portion (YearData) using the "get_1_month" pattern.
And it works great.
The log shows the 12 months of data as a big chunk in DataRecord 0, and then after the DataExtract script is run, there is a separate DataRecord (0,1,2,3...11) for each month with all the individual values assigned to the variable names in the pattern.
Very cool.
But then the script comes to a halt with an error message.
for( i = 0; i < mydata.getNumDataRecords(); i++ )
{
// Store the current data record in the variable myDataRecord.
xrDataRecord = climdata.getDataRecord( i );
// Write out the data to the file.
out.write( session.getVariable( "Zip" ) + "\t" );
out.write( xrDataRecord.get( "Monthabbr" ) + "\t" );
out.write( xrDataRecord.get( "High" ) + "\t" );
out.write( xrDataRecord.get( "Low" ) + "\t" );
etc.
The error message was: Attempt to invoke method: get() on undefined variable or class name: xrDataRecord : at Line: 15.
All the data is there, sitting in the DataSet.
I just can't access it, and I think it must be due to the scope of the variables.
Suggestions please!
Thanks.
(bump)
Suggestions please?
I'd like to get this going for the weekend.
Thanks.
In your "for" loop, you refer
In your "for" loop, you refer to a DataSet named "myData", but then you're trying to get data out of "climdata" which, as far as I can see isn't in scope. Don't you want to get the individual dataRecords out of "myData"?
my mistake
You're right. I mistakenly took the example from an earlier project.
The line should read -
xrDataRecord = mydata.getDataRecord( i );
same issue.
Can you just paste your real
Can you just paste your real script for me? Use of the <code> and </code> tags will retain its structure.