3 Replies Latest reply on May 16, 2017 7:50 AM by beverly

    JSON script parameters

    mchettle

      I am sure by submitting my ideas here, there will be a good amount of discussion of what might be the best practice and why of using the new JSON functions in FileMaker 16 to convey script parameters.

       

      First I will post my JSON script parameter code, then we can all discuss the pro's and con's. My hope is to move toward a set of common objectives for anyone wanting to use JSON in this way.

       

      The text in Red indicates the keys and values to be used by the executing script.

      The text in Blue is admin information data. (optional).

       

      // keys [ action ; uuid ; keyN ] :: JSON Script Parameter function 20170516v6

       

      Let (

      [

      value1 = "newRecord” ;

      value2 = “indexvalue” ;

      valueN = “?” ; // iterate the next value number.

       

      key1 = "action" ; // used by script to determine the script path.

      key2 = "uuid" ; // used by script to filter what to do the action to or with.

      keyN = “?” ; // iterate the next key number.

       

      // the following data sets are [optional] for admin and qualification processing.

      table = Get ( LayoutTableName ) ;

      layout = Get ( LayoutName ) ;

      utc = Get ( CurrentTimeUTCMilliseconds ) ;

      log = "no" ;

      deviceid = Get ( PersistentID ) ;

      account = Get ( AccountName ) ;

      name = Get ( UserName ) ;

       

      $result = JSONSetElement

        ( $json ;

        [ "@table" ; table ; JSONString ] ;

        [ "@layout" ; layout ; JSONString ] ;

        [ "@runutc" ; utc ; JSONString ] ;

        [ "@log" ; log ; JSONString ] ;

        [ "@deviceid" ; deviceid ; JSONString ] ;

        [ "@useraccount" ; account ; JSONString ] ;

        [ "@username" ; name ; JSONString ] ;

       

        [ key1 ; value1 ; JSONString ] ;

        [ key2 ; value2 ; JSONString ] ;

        [ keyN ; valueN ; JSONString ] // iterated JSON values.

        )

      ]

      ;

      JSONFormatElements ( $result )

      )

       

      The result would be something like :

      {

        "@deviceid" : “123456...90”,

        "@layout" : "",

        "@log" : "no",

        "@runutc" : "63630527735026",

        "@table" : "",

        "@useraccount" : “logged in user”,

        "@username" : “your computer name”,

        "action" : "newRecord",

        "uuid" : "indexvalue"

      }