hopefully this is an easy one for the experts out here. I've been doing some searching and have tried quite a few different possible solutions but this async/sync ordeal is confusing for me.
At any rate, I am attempting to fetch a JSON from an API I wrote. I am getting the value back fine and have verified it in the console log. However, I am trying to copy a specific value in that JSON over to a field within a form.io.
The JS:
fetch('https://example.com/pq-api/pq.php?date=' + data.dateOfService)
.then(response => response.json())
.then(data => console.log(data));
That JSON response looks like:
[
{
"Date": "2020-08-09",
"Time": "06:00:06",
"Account": "Petty Cash",
"Balance": "148.53"
}
]
I am now trying to save the value of 'Balance' to a field within form.io called 'runningBalance'. So, it would need to be something like:
value = jsonData.Balance;
Obviously the last portion is completely wrong, I only know that I need to use "value =" due to the location of this script within the form... but I can't sort out how to assign the Balance portion of the JSON to that 'value'.
Any help is greatly appreciated here!
Another screenshot when using ".then(data => console.log(data[0]));":
The response seems to be an array to instead of doing for example
value=data.Balance;
you do
value=data[0].Balance;