An error occurred while writing the data to a file: null

Hi, I'm trying to do the second tutorial. Currently I'm at the end where I need to save the data, but I'm getting the error "An error occurred while writing the data to a file: null." It's because the dataRecord variable isn't being set. Where should it be set? This is my code, for reference:

FileWriter out = null;

try
{
    session.log( "Writing data to a file." );

    // Open up the file to be appended to.
    out = new FileWriter( "dvds.txt", true );

   // Write out the data to the file.
   out.write( dataRecord.get( "TITLE" ) + "\t" );
   out.write( dataRecord.get( "PRICE" ) + "\t" );
   out.write( dataRecord.get( "MODEL" ) + "\t" );
   out.write( dataRecord.get( "SHIPPING_WEIGHT" ) + "\t" );
   out.write( dataRecord.get( "MANUFACTURED_BY" ) );
   out.write( "\n" );

   // Close up the file.
   out.close();
}
catch( Exception e )
{
   session.log( "An error occurred while writing the data to a file: " + e.getMessage() );
}

Nate, It sounds like you may

Nate,

It sounds like you may be calling your script "After pattern is applied". Instead you need to call it either "After each pattern match" or "Once if pattern matches".

Doing so will allow you to access the DataRecord object in your script since it will be in scope.

-Scott

Hey, thanks for your reply.

Hey, thanks for your reply. In my Details page, under the Extractor Patterns tab, I'm calling the script 'Write data to file' with When to Run as 'After each pattern match.' Let me know if something should be different.

Nate, Ok, next guess, does

Nate,

Ok, next guess, does your extractor pattern text look like the following?

<tr>
<td colspan="2" class="pageHeading~@DATARECORD@~Quantity

When you click the "Test Pattern" button do results come up?

-Scott

Nope

I couldn't get it to look like that. Every time I highlighted the text and tried to change it to ~@DATARECORD@~, it cut it off before Quantity. I figured that would be good enough as I was able to all the relevant values to variables.