Thanks - ok, so the result is not guaranteed. I will have to work on this more until I find the solution.
Like Andrew was saying, I’m pretty sure you just need to add a fallback.
javascript
var raw = @JSON
var json = {};
try {
json = JSON.parse(raw);
} catch (e) {}
try {
json.related_contract[0].contract_number || ""
} catch (e) {
""
}
Thanks - not sure what is going going on but I have understood this gives the correct answer in the record’s fields even through the sample view doesn’t.
Perhaps @Leo could explain what the limitations are in calculation fields regarding JSON strings, etc?
The sample view uses fake placeholder data so you can visualize the result. Assumably it returns a string or number depending on the field referenced. That’s why we add the OR statement ( || ) so there is a fallback to “”. This satisfies the sample view allowing you to save. I hope that helps answers your question.
Got it - thanks. This a bit of a steep learning curve for me
That’s why we’re all here -learning and growing together.