Using calulation field + javascript to parse JSON

Comments

7 comments

  • Marc Høegh

    Hi Ryan,

    The problem here is that when you save your template the calculation field is validated against a sample value that Podio injects - specifically the string "Script field example text"

    Since "Script field example text" is not valid JSON, it results in a JavaScript error when attempted parsed.

    The solution to the problem is a little hacky, but it will work:
    Simply wrap your "JSON.parse()" invocation in a try/catch clause like so:

    try {
      String(JSON.parse(@JSONResponse).id);
    } catch (e) {
       "Could not parse JSON"
    }
    

    Let me hear if this solves your problem or not.

    Regards,

    Marc, Podio

    4
    Comment actions Permalink
  • Permanently deleted user

    I'm interested in this, too. Anyone?

    0
    Comment actions Permalink
  • Permanently deleted user

    I've tried but failed. See details here: https://help.podio.com/hc/communities/public/questions/202223098-How-to-parse-JSON-in-a-calculation-field-?locale=en-us

    0
    Comment actions Permalink
  • Ron Abbate

    PODIO Please follow up on this. There is no response at all.

    0
    Comment actions Permalink
  • Ron Abbate

    That worked for me. Super simple solution. Thanks Marc!

    0
    Comment actions Permalink
  • Permanently deleted user

    Thank you so much Marc, that works!

    0
    Comment actions Permalink
  • PJ Muller

    Hi Marc, just so that we are fully in the loop.

    Could you give us a list of the default values that are used for the other types (date, number, currency, email, ...)? Could help not punching myself in the face whenever the calcs just don't want to get stored.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk