How to Generate multiple JSON files in FTP based on unique ORDERNO

I have a page of records that contains 3 records. 1 order has ORDERNO 000020. Another 2 orders has the same ORDERNO 000021, but has different ordered goods.

In a "preSavePage" hook, I basically changed the data to so that it removes the duplicated ORDERNO and combines them into one with its different goods.

 

Then these records goes into the API call and succeeded. And only when API call succeeded, I want to generate a json file in FTP for these two records to acknowledge that these two orders has been placed. 

Somehow, whenever I run the flow, it is only generating 1 file. I have "skip aggregation" set to true, and one to many set to yes... also tried setting one to many as no... none of them seem to work.

How do I make it so that files will be generated based on the number of records (unique ORDERNO) ?

 

0

Comments

8 comments
Date Votes
  • Tino Liu can you show the whole flow? Does your initial export have 3 order records?

    1
  • Figure: Grab CSV file from FTP, go through preSavePage hook, call API, finally generate files to FTP

    Figure: Initial exports have 3 records (3 rows from csv). 2 records are the same ORDERNO so the preSavePage hook combines them.

    Figure: API only needs to call twice since there's only 2 records

     

    Then, ideally, build JSON document should generate 2 JSON files.

     

    0
  • Tino Liu you should remove the preSavePage script, add a grouping for ORDERNO in the FTP export under the grouping and sorting section, set the page size on the export to 1, then set skip aggregation to true on the import.

    0
  • Thank you Tyler! I'll give it a try! But I seem to have a problem getting my Handlebars template correct for building relative URI.

    Figure: goodsDtoList is a list of objects including ITEMCODE, QUANTITY... The same as the below screenshot from request body

    I have a working handlebars for my request body

    0
  • The reason I did it with preSavePage is because I used it to put a property "goodsDtoList" that basically does the "each" in the handlebars template. And in my build URI template... all i had to do is write "goodsDtoList": ' jsonSerialize data.0.goodsDtoList '

    0
  • Update: Seems like the syntax is correct.. no errors.. but values are not being created

    0
  • I got it working! 

    After adding grouping by ORDERNO, I still created a preSavePage hook and lopped through "data" and created an array of objects within the first index object inside "data". (Not exactly elegant, but it's a working hack).

    Then all I have to do is write...

    "goodsDtoList":' (jsonSerialize data.0.0.goodsList)

    in the API call handlebars template... set FTP file generation set skip aggregation to true and it generated multiple files. Thank you Tyler!

    0
  • Tino Liu glad you figured it out! Whenever I group records, I typically restructure it so it's easier to follow. For example, when you group by ORDERNO, you end up with a rows array where ORDERNO repeats for each row, but I typically like to convert the rows array into a single record object with a lines array. For example, the below screenshot uses a transformation on thee export to convert the rows to a record. You could do this in your preSavePage script as well.

    1

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post