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.
Hi Andrew, I have started using Claude - I must say that I’m pretty impressed with the kinds of things that I can do with it. Do you know if its possible to connect a calculation field directly to it?
I don’t think you can connect Claude directly to a calculation field. But you can ask Claude to format your JS so that you can copy and paste it.
We’re almost finished building out a data set for Claude projects. I’ll share with the class after we do.