Updating a Calculation Field Script via the API

Comments

4 comments

  • Andreas Garnæs

    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 is field_X, where X is a field id. So instead of @Date1 you need do use @[Date1](field_123), where 123 is your field id.

    Hope it helps.

    Best,
    Andreas

    0
    Comment actions Permalink
  • Matthew Ivie

    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.

    0
    Comment actions Permalink
  • Andreas Garnæs

    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
    }
    
    0
    Comment actions Permalink
  • Matthew Ivie

    Thank you! This works! Awesome! :)

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk