Home > Blockchain >  Value not populating in output
Value not populating in output

Time:11-22

Using JOLT I am trying to multiply value of PRICE_PO and QTY_PO value and I am expecting the answer in itemTotalAmount field but itemTotalAmount is not populating in the output file.

Input JSON

{
  "PURCHASE_ORDER_DISPATCH": {
    "MsgData": {
      "Transaction": {
        "PO_POD_HDR_EVW1": {
          "PO_POD_LN_EVW1": {
            "PO_POD_SHP_EVW1": {
              "PRICE_PO": 14.99,
              "QTY_PO": 1
            }
          }
        }
      }
    }
  }
}

JOLT Spec

[
  {
    "operation": "shift",
    "spec": {
      "PURCHASE_ORDER_DISPATCH": {
        "MsgData": {
          "Transaction": {
            "PO_POD_HDR_EVW1": {
              "PO_POD_LN_EVW1": {
                "PO_POD_SHP_EVW1": {
                  "PRICE_PO": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.items.item.marketPrice",
                  "QTY_PO": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.items.item.itemQuantity",
                  "e($.PRICE_PO * $.QTY_PO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.items.item.itemTotalAmount"
                }
              }
            }
          }
        }
      }
    }
  }
]

Expected output with itemTotalAmount-

{
 "integration-inbound:IntegrationDetails": {
   "integrationEntities": {
     "integrationEntity": {
       "integrationEntityDetails": {
         "poDetails": {
           "items": {
             "item": {
               "marketPrice": 14.99,
               "itemQuantity": 1,
               "itemTotalAmount":14.99
             }
           }
         }
       }
     }
   }
 }
}

CodePudding user response:

You can add modify and remove transformations successively to the current spec such as

[
  ...,
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": {
              "*": {
                "*": {
                  "*": {
                    "product": "=divide(1,@(1,itemQuantity))",
                    "itemTotalAmount": "=divide(@(1,marketPrice),@(1,product))"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": {
              "*": {
                "*": {
                  "*": {
                    "product": ""
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

there is no multiply function but divide (or divideAndRound) which is used within the modify transformation, and the auxiliary attribute(product) is deleted by remove spec

the demo on the site enter image description here

  • Related