Support Questions

Find answers, ask questions, and share your expertise

Copy Field value from one list to another using JOLT

avatar
Contributor

Hello,

Could you please help me what i am missing here.. i am trying to copy currency value from currency condition and adding it in calculatePrice array.

Input 

{
  "tiers": [
    {
      "rewards": [
        {
          "rewardId": 8127,
          "changeType": 2,
          "changeAmount": 15,
          "changePercent": null,
          "quantityToDiscount": null,
          "applyInd": 2,
          "rewardsMerch": []
        }
      ],
      "priceRuleAttributes": [
        {
          "type": "CFA",
          "id": "PR_CURR_CONDITION",
          "values": [
            "AED"
          ]
        }
      ]
    },
    {
      "rewards": [
        {
          "rewardId": 8128,
          "changeType": 2,
          "changeAmount": 18,
          "changePercent": null,
          "quantityToDiscount": null,
          "applyInd": 2,
          "rewardsMerch": []
        }
      ],
      "priceRuleAttributes": [
        {
          "type": "CFA",
          "id": "PR_CURR_CONDITION",
          "values": [
            "USD"
          ]
        }
      ]
    }
  ]
}

Spec

[
  {
    "operation": "shift",
    "spec": {
      "tiers": {
        "*": {
          "priceRuleAttributes": {
            "*": {
              "id": {
                "PR_CURR_CONDITION": {
                  "@(2,values[0])": "paths.[&5].currencyCondition[#2].currency"
                }
              }
            }
          },
          "rewards": {
            "*": {
              "changeType": "paths.[&3].calculatePrice[&1].calculationType",
              "changeAmount": "paths.[&3].calculatePrice[&1].amount",
              "changePercent": "paths.[&3].calculatePrice[&1].percentage"
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-default-beta",
    "spec": {
      "paths": {
        "*": {
          "calculatePrice": {
            "*": {
              "currency": "@(0,currencyCondition[&].currency)"
            }
          }
        }
      }
    }
  }
]

Expected output

{
  "paths" : [ {
    "currencyCondition" : [ {
      "currency" : "AED"
    } ],
    "calculatePrice" : [ {
      "calculationType" : 2,
      "amount" : 15,
      "percentage" : null,
      "currency" : "AED"
    } ]
  }, {
    "currencyCondition" : [ {
      "currency" : "USD"
    } ],
    "calculatePrice" : [ {
      "calculationType" : 2,
      "amount" : 18,
      "percentage" : null,
      "currency" : "AED"
    } ]
  } ]
}

 

5 REPLIES 5

avatar
Super Guru

Hi,

I think you can do this part of the first shift spec unless Im missing something:

[
  {
    "operation": "shift",
    "spec": {
      "tiers": {
        "*": {
          "priceRuleAttributes": {
            "*": {
              "id": {
                "PR_CURR_CONDITION": {
                  "@(2,values[0])": "paths.[&5].currencyCondition[#2].currency"
                }
              }
            }
          },
          "rewards": {
            "*": {
              "changeType": "paths.[&3].calculatePrice[&1].calculationType",
              "changeAmount": "paths.[&3].calculatePrice[&1].amount",
              "changePercent": "paths.[&3].calculatePrice[&1].percentage",
              "@(2,priceRuleAttributes[0].values[0])": "paths.[&3].calculatePrice[&1].currency"
            }
          }
        }
      }
    }
  }
]

 

avatar
Contributor

In that case you made it static as priceRuleAttributes array can have multiple dynamic values and its index can be change for PR_CURR_CONDITION.

 

"priceRuleAttributes": [
        {
          "type": "CFA",
          "id": "PR_BRANCH_NAME",
          "values": [
            "MEMBERS"
          ]
        },
        {
          "type": "CFA",
          "id": "PR_PRICE_RULE_PROMO",
          "valueBoolean": true
        },
        {
          "type": "CFA",
          "id": "PR_TARGET_SEGMENT",
          "values": [
            "PAS_LOGGEDIN",
            "LOGGEDIN",
            "PAS_NOT_LOGGEDIN"
          ]
        },
        {
          "type": "CFA",
          "id": "PR_CURR_CONDITION",
          "values": [
            "AED"
          ]
        }
      ]

 

avatar
Super Guru

I guess Im having hard time understanding what are you trying to do . In the first post you said you are just wanting to copy the value from Currency Condition into Calculate Pricee, so I assumed there is always going to be one value in the Currency Condition Array, but now you are saying can be dynamic and it can change . So what are the rules here in case you have multiple values? how do you decide? Can you specify the different scenarios that you would have in the input and what is the expected output for each ?

avatar
Contributor

Sorry i shared simplified input JSON, here is input so priceRuleAttributes array can have more than one value or can be empty.

{
  "tiers": [
    {
      "rewards": [
        {
          "rewardId": 8127,
          "changeType": 2,
          "changeAmount": 15,
          "changePercent": null,
          "quantityToDiscount": null,
          "applyInd": 2,
          "rewardsMerch": []
        }
      ],
      "priceRuleAttributes": [
        {
          "type": "CFA",
          "id": "PR_BRANCH_NAME",
          "values": [
            "MEMBERS"
          ]
        },
        {
          "type": "CFA",
          "id": "PR_PRICE_RULE_PROMO",
          "valueBoolean": true
        },
        {
          "type": "CFA",
          "id": "PR_TARGET_SEGMENT",
          "values": [
            "PAS_LOGGEDIN",
            "LOGGEDIN",
            "PAS_NOT_LOGGEDIN"
          ]
        },
        {
          "type": "CFA",
          "id": "PR_CURR_CONDITION",
          "values": [
            "AED"
          ]
        }
      ]
    },
    {
      "rewards": [
        {
          "rewardId": 8128,
          "changeType": 2,
          "changeAmount": 18,
          "changePercent": null,
          "quantityToDiscount": null,
          "applyInd": 2,
          "rewardsMerch": []
        }
      ],
      "priceRuleAttributes": [
        {
          "type": "CFA",
          "id": "PR_BRANCH_NAME",
          "values": [
            "MEMBERS"
          ]
        },
        {
          "type": "CFA",
          "id": "PR_CURR_CONDITION",
          "values": [
            "USD"
          ]
        }
      ]
    }
  ]
}

 

Output

{
  "paths" : [ {
    "currencyCondition" : [ {
      "currency" : "AED"
    } ],
    "calculatePrice" : [ {
      "calculationType" : 2,
      "amount" : 15,
      "percentage" : null,
      "currency" : "AED"
    } ]
  }, {
    "currencyCondition" : [ {
      "currency" : "USD"
    } ],
    "calculatePrice" : [ {
      "calculationType" : 2,
      "amount" : 18,
      "percentage" : null,
      "currency" : "USD"
    } ]
  } ]
}

avatar
Super Guru

Hi,

Sorry for the delay. See if this will work:

 

[
  {
    "operation": "shift",
    "spec": {
      "tiers": {
        "*": {
          "priceRuleAttributes": {
            "*": {
              "id": {
                "PR_CURR_CONDITION": {
                  "@(2,values[0])": "paths.[&5].currencyCondition[#2].currency"
                }
              }
            }
          },
          "rewards": {
            "*": {
              "changeType": "paths.[&3].calculatePrice[&1].calculationType",
              "changeAmount": "paths.[&3].calculatePrice[&1].amount",
              "changePercent": "paths.[&3].calculatePrice[&1].percentage",
              "@(2,priceRuleAttributes)": {
                "*": {
                  "id": {
                    "PR_CURR_CONDITION": {
                      "@(2,values[0])": "paths.[&7].calculatePrice[&4].Currency"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]