Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
protogrid:agents [2021-06-23 11:25] – Hinweis auf Performance-Beeinträchtigung von include_cards eingefügt. dru | protogrid:agents [2023-01-16 23:16] (current) – [Example] dru | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Agents ====== | ====== Agents ====== | ||
Agents run periodically and execute code specified by the user. | Agents run periodically and execute code specified by the user. | ||
- | |||
- | Note: Agents are only available in environments that run Protogrid 2.1 or higher. | ||
===== Setup ===== | ===== Setup ===== | ||
Line 11: | Line 9: | ||
==== Example ==== | ==== Example ==== | ||
- Create a Proto with a DateTime Field and a Text Field. Copy the key of the Text Field. | - Create a Proto with a DateTime Field and a Text Field. Copy the key of the Text Field. | ||
- | - Create a user profile with rights to edit the proto created above. | + | - Create a user profile with rights to edit the proto created above but without Environment Administrator rights. |
- | - Create an Agent Library, specify the user created above as context user and copy the following code. Replace the value of //defkey_status_field// with the key from above. | + | - Create an Agent Library, specify the user created above as context user and copy the following code. Replace the value of //fieldkey_status_field// with the key from above. |
+ | - Create a Proto for parameter values with a Text Field, copy the key of the Text Field and replace // | ||
- Add this Agent Library to your Proto. | - Add this Agent Library to your Proto. | ||
- Based on this proto, create some cards where the date lies within the next 60 minutes. Wait one hour. | - Based on this proto, create some cards where the date lies within the next 60 minutes. Wait one hour. | ||
Line 19: | Line 18: | ||
<code javascript> | <code javascript> | ||
function agent_library() { | function agent_library() { | ||
- | var defkey_status_field | + | var fieldkey_status_field |
var cardkey_parameter_deadline_reached = ' | var cardkey_parameter_deadline_reached = ' | ||
- | var defkey_message_deadline_reached | + | var fieldkey_parameter_value |
// Make sure that this function does not return until all operations and JSON-API requests are completed / fulfilled. | // Make sure that this function does not return until all operations and JSON-API requests are completed / fulfilled. | ||
Line 35: | Line 34: | ||
// Here is an example for an authenticated axios GET request: | // Here is an example for an authenticated axios GET request: | ||
try { | try { | ||
- | var data = await axios.get(baseurl + ' | + | var response |
' | ' | ||
' | ' | ||
Line 42: | Line 41: | ||
console.log(' | console.log(' | ||
- | var loaded_card = monkey_patch_card(data.result); | + | var loaded_card = monkey_patch_card(response.data.result); |
- | var loaded_message = loaded_card.get_value(defkey_message_deadline_reached, 'Frist abgelaufen' | + | var loaded_message = loaded_card.get_value(fieldkey_parameter_value, 'Frist abgelaufen' |
- | card.set_element_value(defkey_status_field, loaded_message); | + | card.set_element_value(fieldkey_status_field, loaded_message); |
return true; | return true; | ||
Line 61: | Line 60: | ||
===== Execution ====== | ===== Execution ====== | ||
- | Agents are by default checked every hour (this can be modified for your environment, | + | Agents are by default checked every hour (this can be modified for your environment, |
+ | |||
+ | Agents run in the context of a specific user profile | ||
While an agent is running in the context of a specific card, it is also possible to load and save other cards by calling the JSON API endpoints using axios. A valid axios module is given in the // | While an agent is running in the context of a specific card, it is also possible to load and save other cards by calling the JSON API endpoints using axios. A valid axios module is given in the // |