This can be repeated for each parameter your script requires. With option two, possibly the most useful, you can set a single parameter from the input to a local variable using the following line: Extract only the parameters you need from the script parameter as you use them. Set each parameter needed to a local variable in its own JSONGetElement line at the top of your script.ģ. Explode each of the values in the array to a local variable using a loop or custom function.Ģ. Next, you’ll want to retrieve your values from the JSON string. Once we’ve passed our JSON array to our script in a parameter, this is where the benefits come in.įirst, you’ll want your script to verify the received parameter is valid JSON: Reading JSON – unpacking your script parameters I find the third parameters pretty easy to remember, but regardless of how you write your JSON, the biggest benefit to passing parameters in JSON is that no matter which method you use to construct it, the string that is passed to the receiving script is always going to adhere to a standardized structure. Custom functions can be used to make common tasks easier and, in this case, they could obviate the need for remembering the third parameter by having it in the name, like “JSONSetNumber”. One could make this easier to write by creating FileMaker custom function to help with JSON creation. The following statement will create a JSON object with 3 name/value pairs (three script parameters) in it:Īgain, it guesses this is an array and discards the restĪs you can see, those not familiar with JSON may find this structure a bit difficult to write and may dismiss JSON as an option at this point. Download the example file here: JSONScriptParameters.fmp12 Writing JSON in FileMaker 16įirst, let’s look at the method for writing a JSON string with multiple parameters. You don’t need the file to follow along with this article, but there are some scripts you may want to copy from it when you’re parsing your own JSON. I’ve put together an example file showing how I like to write and read JSON in this context. ![]() ![]() (Spolier: Yes) But there are a few things to keep in mind and they’re mostly around writing JSON (as opposed to reading it). Is formatting script parameters as JSON an improvement?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |