Updating a Calculation Field Script via the API
So i've tried to update a calculation field script via the API (using itDuzzit) and it doesn't seem to work, i'm using the EXACT response from doing a "Get app field" call straight from the sandbox. The calc 'updates' but it ignores the chosen 'delta' value and therefore always moves the field to the top (delta value = 0) , and deletes the script portion of the calculation field. Am I doing something wrong, or is this not possible?
Here is what I used:
API URL (PUT)
Message Body
{
"status": "active",
"external_id": "calculation-4",
"config": {
"default_value": null,
"description": null,
"settings": {
"script": "moment(@Date1).format(\"ww\")",
"color": null,
"expression": null,
"time": null,
"calendar": null,
"decimals": null,
"return_type": "text",
"unit": null
},
"required": false,
"mapping": null,
"label": "TEST",
"visible": true,
"delta": 4,
"hidden": false,
"unique": false
},
"field_id": 81411538,
"label": "TEST",
"type": "calculation"
}
This the HTTP response I get back.
{"revision":40}
It does however update the label, but that is the only thing that works.
-
Hi Matthew,
The format of variables in a calculation script is unfortunately not very well documented -- you may be the first one outside of Podio to do this ;)
The format of variables in calculation fields is
[label](variable-identifier)
. The label is only for showing in the UI. There are a number variable identifiers, the simplest of which isfield_X
, whereX
is a field id. So instead of@Date1
you need do use@[Date1](field_123)
, where123
is your field id.Hope it helps.
Best,
Andreas -
I know how the variables work actually, (inspect element helps), I do see I did that wrong, but I'm talking about using an API Call to set the actual script in a calculation field (like you would when you are modifying the template). The docs claim it should work, but it literally will just not do it. It always blanks out the whole calculation. Does this make sense?
I just tried to do this in the message body (updated with proper variable format)
{ "status": "active", "external_id": "calculation-4", "config": { "default_value": null, "description": null, "settings": { "script": "moment(@[Date1](field_80809972)).format(\"ww\")", "color": null, "expression": null, "time": null, "calendar": null, "decimals": null, "return_type": "text", "unit": null }, "required": false, "mapping": null, "label": "TEST", "visible": true, "delta": 4, "hidden": false, "unique": false }, "field_id": 82457995, "label": "TEST 10/28", "type": "calculation" }
And it moved the field to 0 Delta, and didn't change the script, its just a blank calculation field.
-
Please try passing in only config:
{ "default_value": null, "description": null, "settings": { "script": "moment(@[Date1](field_80809972)).format(\"ww\")", "color": null, "expression": null, "time": null, "calendar": null, "decimals": null, "return_type": "text", "unit": null }, "required": false, "mapping": null, "label": "TEST", "visible": true, "delta": 4, "hidden": false, "unique": false }
Please sign in to leave a comment.
Comments
4 comments