Athento allows you to configure a field that performs an external request to obtain and display the available values that you will be able to select.
To do this, you must first create a field of type “selection” or “multiple selection” and then select the subtype “External request”.
Once you have chosen this option, access the advanced administration of the field. At the bottom of this section you will find the “Choice API REST Metadata Type Configs” section, where you must configure the following attributes:
- Request method path (Required): Specifies the path of the method that will be in charge of making the request to obtain the options.
- Username (Optional): Username that will be used to make the request.
- Password (Optional): Password to be used in the request.
The method configured in “Request method path” must be a Python function that meets the following requirements:
- Receive five arguments:
- username: configured username.
- password: configured password.
- page: Current page of the selector.
- pageSize: Number of elements per page in the selector.
- request_search: Search term entered by the user in the selector.
2. Make a call to an external URL using these arguments.
3. Return a dictionary with the following structure:
-
{ 'entries': [ {'value': 'opcion1', 'label': 'Opción 1'}, {'value': 'opcion2', 'label': 'Opción 2'} ], 'hasMore': True # Indica si hay más opciones disponibles para paginación. }
Example of implementation:
def request(**kwargs):
resultado = <llamada_a_url_externa(argumentos)>
opciones = <mapeado_de_opciones_a_partir_del_resultado>
return {
'entries': opciones,
'hasMore': <determinar_si_existen_más_opciones_o_no_a_partir_del_resultado>
}
You can also include additional data in the options if you need more information in each one. For example:
{
'entries': [
{'value': '123', 'label': 'Cliente A', 'email': 'clientea@email.com'},
{'value': '456', 'label': 'Cliente B', 'email': 'clienteb@email.com'}
],
'hasMore': False
}
With this configuration, the field will be able to dynamically obtain the options from an external source, facilitating the management and updating of the data in Athento.
Example:
You can also return additional data in the options. Below is an example returning additional data in the options.
Comments
0 comments
Please sign in to leave a comment.