How to update values in a collection record list using a workflow loop from a JSON array?

Hello!

I am trying to learn about workflows, and I need to update currency rates in the Currencies collection. The source is a link with data in JSON format. I receive the data via an HTTP request in node 1, then transfer it to node 2 to parse the data ( JSON calculation), and then I want to use the Cycle node and the Update node to actually update the value in the currency exchange rate field.

I think I’ve set everything up (up to the Loop node, I can’t get it to work here…) - I get the data in the format I need at node 2 “JSON calculation”:

[
  {
    "code": "AUD",
    "rate": 53.1079
  },
  {
    "code": "AZN",
    "rate": 46.8998
  },
  {
    "code": "DZD",
    "rate": 61.5323
  },
  {
    "code": "GBP",
    "rate": 107.1167
  },
  {
    "code": "AMD",
    "rate": 20.8842
  },
  {
    "code": "BHD",
    "rate": 212.001
  },
  {
    "code": "BYN",
    "rate": 27.0426
  },
  {
    "code": "BGN",
    "rate": 47.7523
  },
  {
    "code": "BOB",
    "rate": 11.5383
  },
  {
    "code": "BRL",
    "rate": 14.701
  },
  {
    "code": "HUF",
    "rate": 24.3687
  },
  {
    "code": "VND",
    "rate": 31.7042
  },
  {
    "code": "HKD",
    "rate": 10.2586
  },
  {
    "code": "GEL",
    "rate": 29.5393
  },
  {
    "code": "DKK",
    "rate": 12.5043
  },
  {
    "code": "AED",
    "rate": 21.7099
  },
  {
    "code": "USD",
    "rate": 79.7296
  },
  {
    "code": "EUR",
    "rate": 93.5626
  },
  {
    "code": "EGP",
    "rate": 16.7732
  },
  {
    "code": "INR",
    "rate": 88.2079
  },
  {
    "code": "IDR",
    "rate": 47.8339
  },
  {
    "code": "IRR",
    "rate": 12.1149
  },
  {
    "code": "KZT",
    "rate": 15.332
  },
  {
    "code": "CAD",
    "rate": 57.8841
  },
  {
    "code": "QAR",
    "rate": 21.9037
  },
  {
    "code": "KGS",
    "rate": 91.1716
  },
  {
    "code": "CNY",
    "rate": 11.2726
  },
  {
    "code": "CUP",
    "rate": 33.2207
  },
  {
    "code": "MDL",
    "rate": 47.057
  },
  {
    "code": "MNT",
    "rate": 22.4919
  },
  {
    "code": "NGN",
    "rate": 54.7569
  },
  {
    "code": "NZD",
    "rate": 46.3707
  },
  {
    "code": "NOK",
    "rate": 78.9809
  },
  {
    "code": "OMR",
    "rate": 206.3454
  },
  {
    "code": "PLN",
    "rate": 22.1305
  },
  {
    "code": "SAR",
    "rate": 21.2612
  },
  {
    "code": "RON",
    "rate": 18.3683
  },
  {
    "code": "XDR",
    "rate": 108.9401
  },
  {
    "code": "SGD",
    "rate": 61.7198
  },
  {
    "code": "TJS",
    "rate": 86.3136
  },
  {
    "code": "THB",
    "rate": 25.1878
  },
  {
    "code": "BDT",
    "rate": 65.1481
  },
  {
    "code": "TRY",
    "rate": 18.7279
  },
  {
    "code": "TMT",
    "rate": 22.7799
  },
  {
    "code": "UZS",
    "rate": 66.1796
  },
  {
    "code": "UAH",
    "rate": 18.861
  },
  {
    "code": "CZK",
    "rate": 38.5652
  },
  {
    "code": "SEK",
    "rate": 86.1183
  },
  {
    "code": "CHF",
    "rate": 100.314
  },
  {
    "code": "ETB",
    "rate": 51.3916
  },
  {
    "code": "RSD",
    "rate": 79.7527
  },
  {
    "code": "ZAR",
    "rate": 47.3544
  },
  {
    "code": "KRW",
    "rate": 54.2563
  },
  {
    "code": "JPY",
    "rate": 51.2138
  },
  {
    "code": "MMK",
    "rate": 37.9665
  }
]

However, I am having difficulties further on. I am reading the documentation JSON Calculation - NocoBase Documentation and trying to make the settings as in the example, but I do not see in the loop settings how to find the path “…Loop Target / ID” and “Loop Target / Total Price” as in the example.


That is, how did the variables from the JSON calculation node get into the Loop node (the image shows the JSON query node, but I think this is just outdated information)?
I did the same as in the example, i.e. I added Properties mapping to JSON calculation.

Example from Docs:

I configured the Loop node

However, after I configured the Loop node, I tried to select the “ISO” and “Value Rate” variables (but they are configured in the JSON calculation node, how can they get into the Loop node?), but I cannot find them in the Loop node, the path just ends at “Loop Target” and there is no further selection of values.

Maybe I’m configuring something incorrectly and have missed something? Maybe I’ve constructed the expression or variables in the above nodes incorrectly? I would appreciate any help!

Hello, the loop node is configured to the JSON compute node object, not to a specific field.

Hello! I didn’t understand your answer, I apologize, I am not an experienced developer yet, could you explain in more detail what I did wrong? Or give me a small example? I couldn’t figure out from the documentation how the chain of nodes is structured in automation and what settings are there (especially in the Loop node). I would be grateful for any help!

Set the “Loop target” of the Loop node to “Node result / JSON calculation”.

1 Like

Yes, it worked! Thank you very much! For some reason, I was sure that in “Loop target” it was necessary to specify the final element of the “path/chain,” but all I had to do was specify the path to the final JSON parameters from “Properties mapping.” That’s great, I’m very happy! :star_struck: