Service variables
Creating variables, filling in values, auto-save, and employee access.
Machine translation
Variables store the settings of a specific service in a company: for example, the connection address or report parameters. The values are common to all employees who work with this service.
Settings and access rights
In Administrator → Services open the saved embedded service and the tab Variables after the preview. Click Create a variable, enter the name in Latin letters and select Text, Number, Yes/no or JSON. The name starts with a letter and contains up to 64 characters: letters, numbers, _, . or -. The description is optional, up to 500 characters. Switch Set the value allows you to keep the definition blank; turning it off when editing clears the previous value. The name of the created variable does not change. The type can be changed along with the new appropriate value or after cleaning.
The value is edited directly in the list line, without opening a separate window. A field is used for text and numbers, a selection list is used for the "Yes/no" value, and a text area that can be enlarged for JSON. The value is saved automatically after a short pause; exiting the text field saves it immediately. The clear button removes the content, preserving the definition itself. The verification or server error is shown next to the field, and the entered data remains on the screen.
An administrator can create and change variables with the right to edit services and the ability to Applications in the subscription. The variables of one service are not visible in another service or another company. Keep in mind that their values can be used by employees with access to the service itself.
If the value is not saved
Check if the value matches the selected type: the numeric field must contain a number, and JSON requires the correct text in this format. If another administrator changed the variable at the same time, update the list and check the current value before re-entering it.
If there are problems with the connection, the error appears next to the field, and the entered text remains on the screen. Wait for the connection to be restored and repeat the change. If the service could not load the variables, it will show an error instead of running with incomplete settings.
Usage in the service code
Synchronous reading, without await and without a request to the server at each request:
const apiToken = synchra.getVariable('api_token');
const settings = synchra.getVariable('settings'); // JSON тоже возвращается сразу
const info = synchra.getVariableInfo('settings'); // is_set, revision, type и другие поля
await synchra.setVariable('settings', { enabled: true }, { revision: info.revision });
const updated = synchra.getVariable('settings'); // уже обновлённое локальное значение
getVariable() returns the value directly; for an empty variable — undefined. The specified JSON null returns as null. An unknown name causes an error. Objects are returned in copies: changing an object by itself does not save anything. Use asynchronous mode for recording setVariable(); upon successful response, the local snapshot is updated. If there is a recording error, it does not change. An optional revision protects against overwriting someone else's change (error 409).
The snapshot is uploaded when the service is opened; changes from other open instances appear the next time it is opened. In the preview, the entry changes only the local test data, without saving it in the company. Up to 100 variables per service are allowed, and up to 64 KiB of JSON per value. The values are available to the executable code and to employees with access to the service: do not keep secrets here that cannot be disclosed to these employees.
Variables in the extension store
When publishing an embedded service or package, the store receives definitions of variables, but not their values: just the name, type, and description. Empty variables are created for the buyer, which he fills in the settings of the installed service. Before the first launch, explain the required values in the product description; check the blank settings via getVariable() or getVariableInfo() and show the user a clear message.
Updating an installed product adds new definitions, preserving the already created definitions and customer values. Changing the seller's type does not overwrite the buyer's existing definition; plan for compatibility of code versions. Reinstalling the same version does not reset the data. The local source ZIP template does not contain variable definitions yet - they are transferred through the store using a separate server package format.