Defining Repeatable Elements in JSON Filter

Cloud_Business.png

If a JSON element occurs in your JSON data multiple times, it is a repeatable element. Usually, a repeatable element contains data for a single label template. Repeatable items produce multiple labels populated with relevant data.

To indicate that you want to use data from all repeatable elements, and not just from the first one:

  1. Select the element and define it as a Data block.

  2. Enable the Repeatable element option.

UUID-8cd03b89-bc59-8a9a-0f71-cb27d3d850d8.png

If the filter contains definition of elements defined as data block / repeatable element, the Use Data Filter action displays repeatable elements with nested placeholders. All actions nested below such a placeholder execute only for data blocks at this level.

Example

The "item" element is defined as both – Data block and Repeatable element. This instructs the filter to extract all occurrences of the array, not just the first one. In this case, the "item" should be defined as the sub-level in Use Data Filter action. You must nest the actions Open Label and Print Label under this sub-level placeholder, so they are going to be looped for as many times as there are occurrences of the "item" element. As shown in the example below, for three times.

{
    "NICELABEL_JOB": {
        "TIMESTAMP": "20130221100527.788134",
        "USER": "PGRI",
        "IT_LABEL_DATA": {
            "item": [
                {
                    "LBL_NAME": "goods_receipt.nlbl",
                    "LBL_PRINTER": "Production01",
                    "LBL_QUANTITY": "1",
                    "MAKTX": "MASS ONE",
                    "MATNR": "28345",
                    "MEINS": "KG",
                    "WDATU": "19.01.2012",
                    "QUANTITY": "1",
                    "EXIDV": "012345678901234560"
                },
                {
                    "LBL_NAME": "goods_receipt.nlbl",
                    "LBL_PRINTER": "Production01",
                    "LBL_QUANTITY": "1",
                    "MAKTX": "MASS TWO",
                    "MATNR": "28346",
                    "MEINS": "KG",
                    "WDATU": "11.01.2011",
                    "QUANTITY": "1",
                    "EXIDV": "012345678901234577"
                },
                {
                    "LBL_NAME": "goods_receipt.nlbl",
                    "LBL_PRINTER": "Production01",
                    "LBL_QUANTITY": "1",
                    "MAKTX": "MASS THREE",
                    "MATNR": "27844",
                    "MEINS": "KG",
                    "WDATU": "07.03.2009",
                    "QUANTITY": "1",
                    "EXIDV": "012345678901234584"
                }
            ]
        }
    }
}

Warning

JSON data filter with nested data block duplicates values from previous assignment area if a variable is defined in the first block but not in the second. For example, you print two labels. In the first assignment area, you defined a variable "manufacturer_serial". In the second assignment area, this variable is not present.

{
  "jobs": [
    {
      "data": [
        {
          "manufacturer_serial": "706583012001",
          "package_code": "AA792CY"
        }
      ],
      "label_filename": "serial_number_label.nlbl",
      "print_quantity": 1,
      "printer_name": "Warehouse_printer_09"
    },
    {
      "data": [
        {
          "package_code": "BE273XS"
        }
      ],
      "label_filename": "serial_number_label.nlbl",
      "print_quantity": 1,
      "printer_name": "Warehouse_09"
    }
  ]
}

The expected result would be the second label without "manufacturer_serial" data. But in the actual print, the second label would contain "manufacturer_serial" value from the first label, which is 706583012001.

There are three possible solutions:

  • Avoid nested data blocks.

  • Define variable values as empty values ("") if variables are not used in nested data blocks.

          "data": [
            {
              "manufacturer_serial": "",
              "package_code": "AA792CY"
            }
  • Use conditions on actions to set variables.

  • Use string manipulations when detected missing variables.