Make buttons and change the base's code
Make a button that does several steps with one click, with no code, and read, change and try the base’s code where it sits.
A button's Open a form step opens a new item's form filled in from the item you are on, and saves nothing until you do. The example shop's Order again opens a new order's form filled in from the order you are on, its lines included. Its customer is locked: shown, not editable, with "Set by Order again" under it. Nothing is saved until you click Save, and leaving the form stores nothing.
- Under After saving, an open step goes to the new item, or comes back to the item the button was on.
- Duplicate opens the same kind of form with nothing locked (Open an item’s page: comments, history, Follow and Duplicate).
The base's code is JavaScript kept in the base itself, with its versions like the rest, which the base runs where fields, rules and steps cannot say what your base should do, such as a call to another company's system, a PDF made on the server or a total worked out over several lists. The assistant writes it when you ask (Add buttons and behaviour with the assistant), and the base's builders read it, change it and try it where it sits. Reading and changing the code, its run log and its test runs are for the base's builders.
Code sits in four places:
- a button's Run code step, on its table's Custom actions page (Make a button that does several steps, with no code): it runs with the button's other steps, as the person who clicks;
- an automation's Run code action, on the automation's page (Run actions when an item changes): it runs as the base, after a change, on a schedule, or when a webhook or a mail comes in;
- a field Computed by code, in the field's box on the Fields page (Work a value out with a computed field (a formula)): its value is worked out each time the item is read;
- the table's Form code, on its General page, which fills in a form's values while it is filled (Give new items default values).
- In Builder, open the table, then the place. To add code, pick Run code as a button's step or an automation's action, or switch on a field's Computed by code or the table's Form code. To remove it, delete the step or the action, or switch it off.
- Write or change the code in its box. Tab puts in a tab, as in any code editor; Shift+Tab leaves the box.
- Under the box, pick the item to try it on, where the code runs on one, such as On the order, and click Test run. Input (JSON) holds what the code is given besides the item, such as the answers of a button's form. The code runs on that item as the box holds it now, saved or not, and nothing is saved and nothing is sent. You see what it gives back, a file as a link to download it, the lines it wrote to its log, and the mails and the calls to other services it would have sent; or, when it fails, why, with the line and column.
- Save as you save the rest: a button's, a field's or the Form code's change with Save table, an automation on its page. Code with a mistake, such as a misspelt name, or an empty box ("Write the code") is refused, with what is wrong under its box, such as "Line 3, column 7: …", and nothing changes. A change of code alone applies at once.
See the runs that failed in the run log
Below each code box, its Run log lists the runs of that code that failed, reached a limit or wrote lines to its log, newest first: when, the line and column, and why, such as "The run used its step budget". Open one to see the lines it wrote to its log; the refresh icon fetches the latest. The assistant reads the same log when you tell it that something did not work.
Dates and times in code
Code reads dates and times as the base shows them, in the base's Time zone in Settings, General: today's date, and an item's date and time, such as when an order was placed. So a mail that a button or an automation sends names the same day and hour the order's page shows, near midnight too. The base's checks, defaults and formulas also take today in the base's time zone. So a date that the form gives as today is today for a check too, and the base does not refuse it as a date in the future.
Limits and details
- Code reaches nothing the base's builders cannot already reach: a button's code works under the rules of the person who clicks, an automation's as the base.
- Code calls only the hosts in the base's Allowed hosts, and Stripe's, api.stripe.com, while the base holds Stripe, and PayPal's, api-m.paypal.com and api-m.sandbox.paypal.com, while it holds PayPal (Add Stripe to your base).
- Code names a secret and never holds its value, and a call that puts a secret where it may not go, such as a key in a body, is refused before anything is sent (Store the keys of other services).
- Each run is limited in the work, the changes, the mails and the calls it makes.