Jump to content

Returning content using ExternalDataFileEx


kjacobson

Recommended Posts

It was suggested to me by Tech Support to use an External Data Base (External Data File) instead of the 30+ resources I had linked to my Web to Print template. They gave me an example to go off of, but the example returns a graphic and I need to return text that is in a record.

 

Here's what I need to do. I have an external txt file that has two columns (Class Title and Class Description). I need the Description to display when a specific title is chosen from the drop down. I have attempted to figure this out, but when I validate the code it always responds "Function does not return a value".

 

Here's the code that was given to me:

 

This is for linking to the external data file:

   Kristal_File = new ExternalDataFileEx("Kristal_database.txt"," ");

   return Kristal_File.valid;

This is for referencing the content in the data file:

Rule("OnJobStart");

   for (i = 1; i < Kristal_File.recordCount+1;i++)

       {

           LocationVar=Kristal_File.GetFieldValue(i, 0);

           LogoVariable=Kristal_File.GetFieldValue(i, 1);

               {

               if (Field("Location") == LocationVar)

                       {

                       var Pic = new FusionProResource(LogoVariable, "graphic", "true");

                        }

               }        

       }

return Pic;

Any help would be greatly appreciated.

Link to comment
Share on other sites

You're pretty close. I think you want to do something like this:

 

In OnJobStart:

 
var filename = "Kristal_database.txt";
Kristal_File = new ExternalDataFileEx(filename, "\t");
if (!Kristal_File.valid)
 Print("Unable to open External Data File: " + filename);

return Kristal_File.recordCount + " records";

Note the "\t" designation for tab-delimited. I've also added some error handling, so that you get a notice at composition time in your log (.msg) file if the external data file can't be opened. At validation time, it will report the number of records (lines) in the external file.

 

Then you want to do this in your graphic rule:

 
if (FusionPro.inValidation)
   Rule("OnJobStart");

var test_val = Field("Destination"); // Field("Location")

for (var i = 1; i <= Kristal_File.recordCount; i++)
{
   var LocationVar = Kristal_File.GetFieldValue(i, 0);
   var LogoVariable = Kristal_File.GetFieldValue(i, 1);
   if (test_val == LocationVar)
       return new FusionProResource(LogoVariable, "graphic", "true");
}

Print("Logo not found for " + test_val);
return NullResource();

Note the extra error handling here as well, and the use of NullResource() at the end if nothing is found. You might also want to test for the existence of the graphic, similar to the logic here.

Link to comment
Share on other sites

Thanks for all your help Dan.

 

I was actually looking for code that would return text from the external database file. I think I figured it out.

 

Here's the code that loads the External File in the JavaScript Globals:

var filename = "classes_database.txt";
Classes_File = new ExternalDataFileEx(filename, "\t");
if (!Classes_File.valid)
 Print("Unable to open External Data File: " + filename);

 

Here's the code that calls the content of the External File:

if (!Classes_File.valid)
 return "Failed to load external file";
var Desc = Classes_File.FindRecord("Title", Field("C1Class1Title"));
return Classes_File.GetFieldValue(Desc, "Description");

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...