1 Notifications / Action Triggers
2 -------------------------------
7 indexterm:[action triggers, event definitions, notifications]
9 Action Triggers give administrators the ability to set up actions for
10 specific events. They are useful for notification events such as hold notifications.
12 To access the Action Triggers module, select *Administration* -> *Local Administration* -> *Notifications / Action triggers*.
16 You must have Local Administrator permissions to access the Action Triggers module.
19 You will notice four tabs on this page: <<event_definitions, Event Definitions>>, <<hooks, Hooks>>, <<reactors, Reactors>> and <<validators, Validators>>.
22 anchor:event_definitions[]
27 Event Definitions is the main tab and contains the key fields when working with action triggers. These fields include:
29 Table 1: Action Trigger Event Definitions
30 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32 |==============================================
33 |*Field* |*Description*
34 | Owning Library |The shortname of the library for which the action / trigger / hook is defined.
35 | Name |The name of the trigger event, that links to a trigger event environment containing a set of fields that will be returned to the <<validators, Validators>> and/or <<reactors, Reactors>> for processing.
36 | <<hooks, Hook>> |The name of the trigger for the trigger event. The underlying action_trigger.hook table defines the Fieldmapper class in the core_type column off of which the rest of the field definitions ``hang''.
37 | Enabled |Sets the given trigger as enabled or disabled. This must be set to enabled for the Action trigger to run.
38 | Processing Delay |Defines how long after a given trigger / hook event has occurred before the associated action (``Reactor'') will be taken.
39 | Processing Delay Context Field |Defines the field associated with the event on which the processing delay is calculated. For example, the processing delay context field on the hold.capture hook (which has a core_type of ahr) is _capture_time_.
40 | Processing Group Context Field |Used to batch actions based on its associated group.
41 | <<reactors, Reactor>> |Links the action trigger to the Reactor.
42 | <<validators, Validator>> |The subroutines receive the trigger environment as an argument (see the linked Name for the environment definition) and returns either _1_ if the validator is _true_ or _0_ if the validator returns _false_.
43 | Event Repeatability Delay |Allows events to be repeated after this delay interval.
44 | Failure Cleanup |After an event is reacted to and if there is a failure a cleanup module can be run to clean up after the event.
45 | Granularity |Used to group events by how often they should be run. Options are Hourly, Daily, Weekly, Monthly, Yearly, but you may also create new values.
46 | Max Event Validity Delay |Allows events to have a range of time that they are valid. This value works with the *Processing Delay* to define a time range.
47 | Message Library Path |Defines the org_unit object for a Patron Message Center message.
48 | Message Template |A Template Toolkit template that can be used to generate output for a Patron Message Center message. The output may or may not be used by the reactor or another external process.
49 | Message Title |The title that will display on a Patron Message Center message.
50 | Message User Path |Defines the user object for a Patron Message Center message.
51 | Opt-In Settings Type |Choose which User Setting Type will decide if this event will be valid for a certain user. Use this to allow users to Opt-In or Opt-Out of certain events.
52 | Opt-In User Field |Set to the name of the field in the selected hook's core type that will link the core type to the actor.usr table.
53 | Success Cleanup |After an event is reacted to successfully a cleanup module can be run to clean up after the event.
54 | Template |A Template Toolkit template that can be used to generate output. The output may or may not be used by the reactor or another external process.
55 |==============================================
58 Creating Action Triggers
59 ~~~~~~~~~~~~~~~~~~~~~~~~
60 . From the top menu, select *Administration* -> *Local Administration* -> *Notifications / Action triggers*.
61 . Click on the _New_ button.
63 image::media/new_event_def.png[New Event Definition]
65 . Select an _Owning Library_.
66 . Create a unique _Name_ for your new action trigger.
68 . Check the _Enabled_ check box.
69 . Set the _Processing Delay_ in the appropriate format. E.g. _7 days_ to run 7 days from the trigger event or _00:01:00_ to run 1 hour after the _Processing Delay Context Field_.
70 . Set the _Processing Delay Context Field_ and _Processing Group Context Field_.
71 . Select the _Reactor_ and _Validator_.
72 . Set the _Event Repeatability Delay_.
73 . Select the _Failure Cleanup_ and _Granularity_.
74 . Set the _Max Event Validity Delay_.
76 image::media/event_def_details.png[Event Definition Details]
78 . If you wish to send a User Message through the Message Center, set a _Message Library Path_. Enter text in the _Message Template_. Enter a title for this message in _Message Title_, and set a value in _Message User Path_.
79 . Select the _Opt-In Setting Type_.
80 . Set the _Opt-In User Field_.
81 . Select the _Success Cleanup_.
83 image::media/event_def_details_2.png[Event Definition Details]
85 . Enter text in the _Template_ text box if required. These are for email messages. Here is a sample template for sending 90 day overdue notices:
89 [%- user = target.0.usr -%]
90 To: [%- params.recipient_email || user.email %]
91 From: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %]
92 Subject: Overdue Items Marked Lost
93 Auto-Submitted: auto-generated
95 Dear [% user.family_name %], [% user.first_given_name %]
96 The following items are 90 days overdue and have been marked LOST.
97 [%- params.recipient_email || user.email %][%- params.sender_email || default_sender %]
98 [% FOR circ IN target %]
99 Title: [% circ.target_copy.call_number.record.simple_record.title %]
100 Barcode: [% circ.target_copy.barcode %]
101 Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
102 Item Cost: [% helpers.get_copy_price(circ.target_copy) %]
103 Total Owed For Transaction: [% circ.billable_transaction.summary.total_owed %]
104 Library: [% circ.circ_lib.name %]
107 [% FOR circ IN target %]
108 Title: [% circ.target_copy.call_number.record.simple_record.title %]
109 Barcode: [% circ.target_copy.barcode %]
110 Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
111 Item Cost: [% helpers.get_copy_price(circ.target_copy) %]
112 Total Owed For Transaction: [% circ.billable_transaction.summary.total_owed %]
113 Library: [% circ.circ_lib.name %]
116 . Once you are satisfied with your new event trigger, click the _Save_ button located at the bottom of the form.
121 A quick and easy way to create new action triggers is to clone an existing action trigger.
124 Cloning Existing Action Triggers
125 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127 . Check the check box next to the action trigger you wish to clone.
128 . Click _Clone Selected_ on the top left of the page.
129 . An editing window will open. Notice that the fields will be populated with content from the cloned action trigger. Edit as necessary and give the new action trigger a unique Name.
132 Editing Action Triggers
133 ^^^^^^^^^^^^^^^^^^^^^^^
135 . Double-click on the action trigger you wish to edit.
136 . The edit screen will appear. When you are finished editing, click _Save_ at the bottom of the form. Or click _Cancel_ to exit the screen without saving.
140 Before deleting an action trigger, you should consider disabling it through the editing form. This way you can keep it for future use or cloning.
143 Deleting Action Triggers
144 ^^^^^^^^^^^^^^^^^^^^^^^^
146 . Check the check box next to the action trigger you wish to delete
147 . Click _Delete Selected_ on the top-right of the page.
149 Testing Action Triggers
150 ^^^^^^^^^^^^^^^^^^^^^^^
152 . Go to the list of action triggers.
153 . Click on the blue link text for the action trigger you'd like to test.
155 image::media/test_event_def.png[Blue Link Text]
157 . Go to the Test tab.
158 . If there is a test available, fill in the required information.
159 . View the output of the test.
161 image::media/test_event_def_output.png[Test Output]
163 WARNING: If you are testing an email or SMS notification, use a test account and email as an example. Using the Test feature will actually result in the notification being sent if configured correctly. Similarly, use a test item or barcode when testing a circulation-based event like Mark Lost since the test will mark the item as lost.
169 Hooks define the Fieldmapper class in the core_type column off of which the rest of the field definitions ``hang''.
173 |=======================
174 | *Field* | *Description*
175 | Hook Key | A unique name given to the hook.
176 | Core Type | Used to link the action trigger to the IDL class in fm_IDL.xml
177 | Description | Text to describe the purpose of the hook.
178 | Passive | Indicates whether or not an event is created by direct user action or is circumstantial.
179 |=======================
181 You may also create, edit and delete Hooks but the Core Type must refer to an IDL class in the fm_IDL.xml file.
189 Reactors link the trigger definition to the action to be carried out.
191 Table 3. Action Trigger Reactors
192 ++++++++++++++++++++++++++++++++
194 |=======================
195 | Field | Description
196 | Module Name | The name of the Module to run if the action trigger is validated. It must be defined as a subroutine in `/openils/lib/perl5/OpenILS/Application/Trigger/Reactor.pm` or as a module in `/openils/lib/perl5/OpenILS/Application/Trigger/Reactor/*.pm`.
197 | Description | Description of the Action to be carried out.
198 |=======================
200 You may also create, edit and delete Reactors. Just remember that there must be an associated subroutine or module in the Reactor Perl module.
208 Validators set the validation test to be preformed to determine whether the action trigger is executed.
210 Table 4. Action Trigger Validators
211 ++++++++++++++++++++++++++++++++++
213 |=======================
214 | Field | Description
215 | Module Name | The name of the subroutine in `/openils/lib/perl5/OpenILS/Application/Trigger/Reactor.pm` to validate the action trigger.
216 | Description | Description of validation test to run.
217 |=======================
219 You may also create, edit and delete Validators. Just remember that their must be an associated subroutine in the Reactor.pm Perl module.