roland
roland

Reputation: 39

JOLT Transformation Boolean in a Sub-Segment of an Array

I have an SAP Idoc with additional customer specific fields as JSON

{
  "E1EDL20": [
    {
      "VBELN": "1234567890",
      "VSTEL": "ZO01",
      "LGNUM": "123",
      "NTGEW": "100.660",
      "ANZPK": "00002",
      "/XYZ/XYZ1234_E1EDL20": {
        "ACTION": "POSTED",
        "CONSIGNMENT": "12345678",
        "FREIGHT_ORDER_EXTERNAL": "S123456789",
        "IN_YARD": "X",
        "IN_YARD_DATE": "20201123",
        "IN_YARD_TIME": "100923"
      },
      "E1ADRM1": [
        {
          "PARTNER_Q": "LF",
          "PARTNER_ID": "0000100000",
          "/XYZ/XYZ1234_E1ADRM1": {
            "SUPPLIER": "X"
          }
        },
        {
          "PARTNER_Q": "OSP",
          "PARTNER_ID": "ZO01",
          "/XYZ/XYZ1234_E1ADRM1": {
            "SUPPLIER": "X"
          }
        }
      ]
    }
  ]
}

Then I tried to remove the root array, rename the fields and do a type conversation of Strings to Integer, Double and Boolean and concatination of a date and time field to a timestamp. Here my Spec.

[
  // Our E1EDL20 array has only one entry -> remove array
  {
    "operation": "cardinality",
    "spec": {
      "E1EDL20": "ONE"
    }
  },
  // Move all contained fields to root level and properly rename them
  {
    "operation": "shift",
    "spec": {
      "E1EDL20": {
        "VBELN": "deliveryInternal",
        "VSTEL": "receivingPoint",
        "LGNUM": "warehouseNumber",
        "NTGEW": "netWeight",
        "ANZPK": "numberOfPackages",
        "/XYZ/XYZ1234_E1EDL20": {
          "ACTION": "action",
          "CONSIGNMENT": "consignment",
          "FREIGHT_ORDER_EXTERNAL": "freightOrderExternal",
          // Rename Content of the field to Boolean String
          "IN_YARD": {
            "X": { "#true": "inYard" },
            "*": { "#false": "inYard" }
          },
          "IN_YARD_DATE": "inYardDateTmp",
          "IN_YARD_TIME": "inYardTimeTmp"
        },
        // Suppliers
        "E1ADRM1": {
          "*": {
            "PARTNER_Q": "supplier[&1].type",
            "PARTNER_ID": "supplier[&1].number",
            "/XYZ/XYZ1234_E1ADRM1": {
              "SUPPLIER": {
                "X": { "#true": "supplier[&2].supplier" },
                "*": { "#false": "supplier[&2].supplier" }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      // Type conversions, String to Double or Integer
      "netWeight": ["=toDouble", null],
      "numberOfPackages": ["=toInteger", null],
      // Type conversions, String to Boolean
      "inYard": ["=toBoolean"],
      "supplier": {
        "*": {
          "belomSupplier": ["=toBoolean"]
        }
      }
    }
  },
  {
    // Create Timestamp for inYardDate
    "operation": "modify-default-beta",
    "spec": {
      "temp_DateYear": "=substring(@(1,inYardDateTmp),0,4)",
      "temp_DateMonth": "=substring(@(1,inYardDateTmp),4,6)",
      "temp_DateDay": "=substring(@(1,inYardDateTmp),6,8)",
      "temp_TimeHours": "=substring(@(1,inYardTimeTmp),0,2)",
      "temp_TimeMinutes": "=substring(@(1,inYardTimeTmp),2,4)",
      "temp_TimeSeconds": "=substring(@(1,inYardTimeTmp),4,6)",
      // Prior to this line, only temporary fields were created from substrings as preparation for the timestamp concatenateion
      "inYardDate": "=concat(@(1,temp_DateYear),'-',@(1,temp_DateMonth),'-',@(1,temp_DateDay),'T',@(1,temp_TimeHours),':',@(1,temp_TimeMinutes),':',@(1,temp_prodTimeSeconds),'Z')"
    }
},
  {
    // Remove temporary substring fields
    "operation": "remove",
    "spec": {
      "temp_DateYear": "",
      "temp_DateMonth": "",
      "temp_DateDay": "",
      "temp_TimeHours": "",
      "temp_TimeMinutes": "",
      "temp_TimeSeconds": "",
      "inYardDateTmp": "",
      "inYardTimeTmp": ""
    }
    }
]

I expected after the JOLT transforamtion an the following output.

{
  "deliveryInternal" : "1234567890",
  "receivingPoint" : "ZO01",
  "warehouseNumber" : "123",
  "netWeight" : 100.66,
  "numberOfPackages" : 2,
  "action" : "POSTED",
  "consignment" : "12345678",
  "freightOrderExternal" : "S123456789",
  "inYard" : true,
  "inYardDate" : "2020-11-23T10:09:Z",
  "supplier" : [ {
    "type" : "LF",
    "number" : "0000100000",
    "supplier" : true
  }, {
    "type" : "OSP",
    "number" : "ZO01",
    "supplier" : true
  } ]
}

But i getting the following output.

{
  "deliveryInternal" : "1234567890",
  "receivingPoint" : "ZO01",
  "warehouseNumber" : "123",
  "netWeight" : 100.66,
  "numberOfPackages" : 2,
  "action" : "POSTED",
  "consignment" : "12345678",
  "freightOrderExternal" : "S123456789",
  "inYard" : true,
  "supplier" : [ {
    "type" : "LF",
    "number" : "0000100000"
  }, {
    "type" : "OSP",
    "number" : "ZO01"
  } ],
  "inYardDate" : "2020-11-23T10:09:Z"
}

Does anyone have an idea how the problem can be solved ?

Upvotes: 0

Views: 618

Answers (1)

mattyb
mattyb

Reputation: 12083

Are you just trying to add supplier: true to your suppliers? I couldn't see any other differences than that. If that's the case you can add this to the end of your chain spec:

{
    // Add supplier = true to supplier elements
    "operation": "shift",
    "spec": {
      "supplier": {
        "*": {
          "#true": "supplier[&1].supplier",
          "*": "supplier[&1].&"
        }
      },
      "*": "&"
    }
}

Upvotes: 1

Related Questions