Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
protogrid:agents [2020-12-22 16:31] – Best-Practices für grössere Berechnungen gemäss KitAjour-Design-Review eingefügt. dru | protogrid:agents [2021-06-06 22:26] – 185.110.184.205 | ||
---|---|---|---|
Line 7: | Line 7: | ||
To set up an agent, there are two necessary steps: | To set up an agent, there are two necessary steps: | ||
* Under Design -> Code, create an Agent Library and add your code to the // | * Under Design -> Code, create an Agent Library and add your code to the // | ||
- | * Under Design -> Proto, select the Proto you want to use and add corresponding the Agent Library | + | * Under Design -> Proto, select the Proto you want to use and add corresponding the Agent Library |
==== Example ==== | ==== Example ==== | ||
Line 19: | Line 19: | ||
<code javascript> | <code javascript> | ||
function agent_library() { | function agent_library() { | ||
- | var defkey_status_field = "3b47a5fe-894d-4580-bc0c-563aa83d9a02"; | + | var defkey_status_field = '3b47a5fe-894d-4580-bc0c-563aa83d9a02'; |
+ | var cardkey_parameter_deadline_reached = ' | ||
+ | var defkey_message_deadline_reached = ' | ||
- | function | + | |
- | //sets the value of a single-value field given by field_key | + | // We recommend to use await / async syntax: https:// |
- | | + | // * card [object]: |
- | | + | // * cookie [string]: |
- | card.design_elements[i]['value'] = value; | + | // * axios [object]: |
- | break; | + | // * baseurl [string]: Contains the base url needed for API requests |
- | } | + | // * appname [string]: Contains the application name |
+ | // most URLs needed for API calls are structured like baseurl + ' | ||
+ | // return value: A boolean. If set to true, it will save the current card | ||
+ | async function on_schedule(card, | ||
+ | // Here is an example for an authenticated axios GET request: | ||
+ | | ||
+ | | ||
+ | ' | ||
+ | ' | ||
+ | } | ||
+ | | ||
+ | console.log('axios GET request finished'); | ||
+ | |||
+ | var loaded_card | ||
+ | var loaded_message = loaded_card.get_value(defkey_message_deadline_reached, | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | console.error(e); | ||
+ | return false; | ||
} | } | ||
- | return card; | ||
} | } | ||
- | + | ||
- | function on_schedule(card, | + | |
- | card = set_value(card, | + | |
- | return card; | + | |
- | } | + | |
- | | + | |
return { | return { | ||
- | set_value: set_value, | ||
on_schedule: | on_schedule: | ||
}; | }; | ||
} | } | ||
+ | |||
</ | </ | ||
===== Execution ====== | ===== Execution ====== | ||
- | Agents are checked every hour. If any DateTime Field on a card has a smaller value than the current time and the Agent has not yet run since that time, the Agent gets triggered and the code in the Agent Library is executed in the context of this card (for Date-Only Fields, the time taken into account is said date, 00:00 GMT). Agents run in the context of a specific user profile. This user's password is automatically reset during the execution process. So this user profile shall only be used for agents and not for physical users. All agent executions are logged in the // | + | Agents are by default |
===== Best Practices for Calculation Code ====== | ===== Best Practices for Calculation Code ====== | ||
In the following, we have compiled some recommendations based on our experience for high stability, performance, | In the following, we have compiled some recommendations based on our experience for high stability, performance, | ||
- It is recommended to use [[protogrid: | - It is recommended to use [[protogrid: | ||
- | | + | |
- Write to as few Relation Fields as possible in the code. Do this only if it is needed for the user interface (e.g. for filtering TableViews). Do this only on Cards that are rarely/ | - Write to as few Relation Fields as possible in the code. Do this only if it is needed for the user interface (e.g. for filtering TableViews). Do this only on Cards that are rarely/ | ||
- | | + | |
- If editing or deleting a Card in the user interface subsequently to calculation has to be prevented, this can be done in both cases by restricting the editing rights ([[protogrid: | - If editing or deleting a Card in the user interface subsequently to calculation has to be prevented, this can be done in both cases by restricting the editing rights ([[protogrid: | ||
- Read/load as few specific/ | - Read/load as few specific/ | ||
- Analogous to the previous point, write as few specific/ | - Analogous to the previous point, write as few specific/ |