How to summerize a detail section in datamapper.

Hello,

I have a PDF that I am running through datamapper and have successfully been able to pull the header and detail info in preparation to using it designer. However … I would like to summarize the detail records before using (ie. from 16 details to 3 summarized). I would then use the 3 summarized records in subsequent reports. I understand that this would probable be javascript but was hoping I could get some examples of this.

Thanks

Jim

1 Like

It’s a bit difficult to provide you with a generic answer because you’re obviously looking for something that’s specific to the type of information found on those PDF files. I would surmise, however, that if you want to thunk 16 detail lines into 3 summary lines, then each of these 16 lines must possess a readily identifiable piece of information allowing you to categorize them into one of the 3 summary lines. For instance, you could be looking at accumulating the number of items ordered, the number of items actually shipped, and the total value of each detail line in a specific currency. In that case, you’d probably want to accumulate these values based on column position in the original file. On the other hand, you may be looking to accumulate Types of items (e.g. parts, services, charges), in which case you’d probably be segregating each line according to a ID mask found in the first column.

You have two ways to go about this:

  1. Create 3 Record-Level variables in which you accumulate (through an action Step) the values you want to summarize at the end. Then, after your detail line loop is complete, you can store those accumulated variables into their own Record-level fields using a standard Extract Step.
  2. At the top of your process, create three empty fields using a standard Extraction step. Add a JS extraction step after your detail line loop to go through all the detail lines that were extracted and summarize the information that you want, then store it into each of the three empty fields

Not sure if that helps you figure things out, but feel free to ask for any additional precision.

Thanks,

Your idea would work, but I was hoping to have something along the lines of …

(the following in part is from another thread)

for(var i in record.tables["detail"]){
    do something;
}

output new table;

i.e. I was hoping I could ‘read’ the built table, and output another table (and of course do stuff in between). Is this possible, and do you have any examples?

Thanks

Jim

You cannot dynamically add new tables (or new fields) as that would break the datamodel’s cardinal rule: uniformity across all records.

However, you can use the same technique I described above by pre-creating another detail table with subrecords that each have a certain number of empty fields. The JS step after your main loop could then fill in those subrecords/fields. Something like:

record.tables.Summary[0].fields.MyFirstField = "some value";
record.tables.Summary[0].fields.MySecondField = "some other value";
...
record.tables.Summary[1].fields.MyFirstField = "some value";
record.tables.Summary[1].fields.MySecondField = "some other value";

Where [0], [1] represent the index of each record in the Summary detail table.

Thank you, this is the route I’m going down.

Is there a specific command to dynamically add records?

No. Best way to do so is to create a loop at the very top of your process to add a certain number of records in your detail table. Set the loop’s condition to:

  • Until Statement is True
  • Maximum iterations on each line: 3 (or any value higher than the number of records to create)
  • Set condition’s left operand to JavaScript with the following code:
    steps.currentLoopCounter;
  • Operator: is equal to
  • Set condition’s right operand to Value: 3 (set this to the actual number of records to create in the table)