Jump to content

External data question


jjdodger

Recommended Posts

This is a theory question, more than a "need it now" question:

 

Can FP create an array of objects from an external data file, on record start,

that can then get parsed/walked through/etc, by another function or functions?

 

As an example, I had to do a project once, where 1 record could have 1 to 200 detail lines, and needed to build a table based on the number of detail lines. The final document was 8 pages long, with the middle 4 being the table, and if a page was blank, print "intentionally left blank" across the middle of the page. It also needed a series of totals printed as the last line of the table, calculated from the data.

 

Is this do-able? The only real example i would need to recreate this would be how to create the object, and how to iterate through it from another rule.

 

I hope this makes sense!

 

Thanks

 

Jeff

Link to comment
Share on other sites

Sure, it's possible; check out the static example below. Just create the array as a JavaScript Global:

globalArray = [];

Then you can populate the array at the start of each record in OnRecordStart:

for (var i = 1; i <=5; i++)
   globalArray.push({
       'recordNumber': i,
       'fieldData': 'Value' + i
   });

 

Then your rule could walk the array:

var result = '';
globalArray.forEach(function(s) {
   result += 'recordNumber: ' + s.recordNumber + '. fieldData: ' + s.fieldData + '.<br/>\n';
});
return result;

 

Then your rule would return:

recordNumber: 1. fieldData: Value1.

recordNumber: 2. fieldData: Value2.

recordNumber: 3. fieldData: Value3.

recordNumber: 4. fieldData: Value4.

recordNumber: 5. fieldData: Value5.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...