David's suggestion is good. Although, if your data fields are always in the same order, but the field names are different, you can simply uncheck the "First row contains field names" box in the Define Data Source Wizard. Then the field names are defined by the Data Fields dialog (FusionPro -> Data Definition -> Input Options -> Fields). You can always tell the composition to skip the first "record" row which contains the field names by creating an OnRecordStart rule with this syntax:

  if (CurrentRecordNumber() == 1)
    FusionPro.Composition.composeThisRecord = false;

In addition, there's an easier (?!) way to determine whether a field exists in your data, without creating an ExternalDataFileEx.

As you know, the Field function throws an error if the specified field name does not exist in your data. What you might not know is that this error is actually an exception, which can be caught using a try/catch block: <http://developer.mozilla.org/en/docs/ Core_JavaScript_1.5_Reference:Statements:try...catch>

So, you can create a function like so:

  function FieldExists(Name)
  {
    try
    {
      Field(Name);
      return true;
    }
    catch (e)
    {
      return false;
    }
  }

Similarly, you can create a function like this:

  function OneOfTheseFields()
  {
    var list = "";
    for (var i = 0; i < arguments.length; i++)
    {
      try
      {
        var result = Field(arguments[i]);
Print("Found Field \"" + arguments[i] + "\", value: " + result);
        return result;
      }
      catch (e)
      {
        if (list)
          list += ", ";
        list += arguments[i];
      }
    }

    var msg = "None of the fields were found: " + list;
    if (FusionPro.inValidation)
      return msg;

    Print(msg);
    return "";
  }

Then you can call this function like so:

  return OneOfTheseFields("Company Name", "Company", "COMP");

The function takes a variable number of arguments, or parameters, which are the field names to look for. Feel free to add as many variations as you need. It will return the value of the first valid field in the list, or, if none of the field names are valid, it will return an empty string and write a message to the log file. The function itself can either go directly inside the rule from which you are calling it, or in your JavaScript Globals. (This logic can also be extended to look for Rule values as well as Field values.)

Dan


P.S. Unfortunately, there's currently no way to iterate through all the field names, without creating an ExternalDataFileEx object. The ability to do that would be a great enhancement, though. Ideally, the fields, rules, and resources would all be properties of an object, so that, say, this:

  FusionPro.Fields["name"];

would be equivalent to this:

  Field("name");

And then you would be able to do something like this:

  for (var i in FusionPro.Fields)
  {
    Print("Field \"" + i + "\", value: " + FusionPro.Fields[i]);
  }

Again, this is just an idea, so that last bit of code won't work right now. Anyone who's reading this, let me know if such a feature would be useful. Maybe I'll try to sneak that enhancement in for one of the next releases.


--
Users of FusionPro Desktop have unlimited free email support. Contact Printable Support at [EMAIL PROTECTED] --
View FusionPro Knowledge Base, FusionPro Samples at
www.printable.com/vdp/desktop.htm

--
You are currently subscribed to fusionpro as: archive@mail-archive.com
To unsubscribe send a blank email to [EMAIL PROTECTED]
--


--
Note:  All e-mail sent to or from this address will be received or otherwise 
recorded by the e-mail recipients of this forum. It is subject to archival, 
monitoring or review by, and/or disclosure to someone other than the recipient. 
Our privacy policy is posted on www.printplanet.com
--

Reply via email to