0

I am implementing a new report system in my company. The transfer of data from ERP to the report builder software is handled with a temporary JSON array.

Within the report builder I can manipulate the data with C#. Currently I am working on a new report for our shipping labels. Sometimes (not always, pseudocode follows) I need to print multiple labels of the same kind.

I think the easiest way to achieve this would be by iterating through the array and duplicate the entries according to my logic. I could put this code in the "DoBeforeYouPrint"-Void of my report then and should get the desired amount of labels.

The data looks something like this (simplified)

  {
    "CustomerID": "1337",
    "ArticleName": "Strawberry",
    "DeliveryWeek": "45",
    "PackagingCount": "50"
  }

Pseudocode:

x = PackagingCount
y = Number of extra rows (labels)

foreach (Entry in DataSource) {

if x < 48 then 
{
y = Math.Ceiling(x / 12)
}

if else x >= 48 then
{
y = Math.Ceiling(x / 60) 
}

if else x > 840 then
{
y = 14
}

for (i = 1 to y) 
{
Duplicate(Entry);
}

}

I need help with a function that will do the duplication of the row and copy all information into an identical new row directly beneath the original row.

Is this possible at all with JSON arrays? I am not a real programmer, I work in a greenhouse.

  • A JSON array `[ ]` can contain many objects `{ }` (each object is separated by a comma). That's the whole purpose of an array. – ProgrammingLlama Nov 26 '21 at 14:34
  • You can create a new output List, adding any number of time the same entry to this list then serializing this list to `Json`. – Hazrelle Nov 26 '21 at 14:37
  • IMHO, it's sounds simpler to just "print the same data twice" on those "sometimes". IOW, instead of mucking with with the data, identify those "sometimes" and see if you can just "print the same data x times" (sort of the print function that asks for number of copies) – EdSF Nov 26 '21 at 14:41
  • I see. In my case I think the objects are the orderlines which were selected through an SQL query in my ERP. This is just the way my report-builder is handling the data. I can do further aggregations of the data within my report with no problems. Here I want to do the opposite though. – Arne Richardsen Nov 26 '21 at 14:42
  • @EdSF That was my original intention but the actual code is hidden. I will continue to try and find that function though. I have also asked the developers. This was just my idea for a quick solution. – Arne Richardsen Nov 26 '21 at 14:50
  • What about just filtering the data for the "id" (assuming that some "key" exists) you're looking for to print x times? You're still not mucking with how the data is built, just "selecting" from the resulting dataset (built by that hidden process) for some other purpose. – EdSF Nov 29 '21 at 02:34
  • If you are asking whether you can generate JSON with duplicated keys, then you can, see [How to serialize and deserialize a JSON object with duplicate property names in a specific order?](https://stackoverflow.com/q/68069271/3744182). However, such JSON will almost certainly be **misinterpreted** by the receiving system. See [Does JSON syntax allow duplicate keys in an object?](https://stackoverflow.com/q/21832701/3744182) for why. **So I am almost sure you don't want to actually do that.** – dbc Dec 01 '21 at 00:33
  • Beyond that, we need more information to help you, namely exactly what you are trying to do. So either 1) The JSON you want to create, or 2) Details about the framework and API you are using to generate your labels. A [mcve] (with code not pseudocode) showing what you have so far and where you are stuck would help us to help you resolve your problem. See: [ask]. – dbc Dec 01 '21 at 00:37
  • I think I will follow the suggested other suggested option. The BeforePrint function should let me repeat these lines as often as I want. If I should need further help there I will post a new thread with my code. Duplicating the data is not as smooth as duplicating the print-order for each control which is what I am actually trying to achieve. How do I close this topic now? – Arne Richardsen Dec 02 '21 at 09:32

0 Answers0