setup duplicate-checking by the field vals we are inserting
actions test where doc received date will add a new doc record with the same type and due-date 1 year from received date
Setup actions test where updating a doc record will update the case field
like doc-received-date where doc_type_id = 1 to update the case - application_received_date
test zap_5
by entering the “case stage
test with using the “+ 5-biz-days” as the val for the due-date
Checklist - Add Section Auto-Action
Scheduled-Auto-Actions
Should have a start and an end date to make it easier to scope
Loop through all of the scheduled ones by the “next-check-date” or something like that
(actions.date_run_next) (where <= current-date)
2023-11-13
trigger_history_fields - val has to be in single-quotes - since its an nvarchar col
trigger_history_fields doesn’t work when there are multiple criteria since there would be two separate trigger_history_fields
select * from trigger_history_fields where db_col = 'type_id' and val = 1 and is_updated = 1
and db_col = 'date_received' and val is not null and is_updated = 1
-
Has to be like this:
declare @trigger_history_id int = 12
select * from trigger_history_fields where trigger_history_id = @trigger_history_id and
(
(db_col = 'type_id' and val = 1 and is_updated = 1)
or
(db_col = 'date_received' and val is not null and is_updated = 1)
)
db_col needs the []
actions - insert record
When insert-record, then we are using the parent_rec_id (so the rec_id should actually be null and be set as an output param)
left join docs as t_1044 on (t_1043.id = t_1044.id) --- this should be t_1044.case_id instead
X - view_tables.is_exclude when we
the for_table_id is for the record being inserted
so, how do we structure the view so that we exclude this line
Essentially, how do we make it so that the we can set the table as the “for_table_id” but we exclude it from the view_tables - from-sql-string and we are building the criteria so its based on the id from the parent_table
maybe we just keep it simple and we have a different - “for_insert_table_id”
which makes it much clearer and allows us to exclude it from the view_tables-sql but still use it as the table it is for
But then how do we select it’s fields because it has to be in the view_tables for us to select the fields we are going to insert
It’s like we need to a special way in view_tables to mark it
like view_tables.is_exclude (or rec_type_id) so it won’t be the table-sql-string
if from_view_id then will generate the Template and do the DataBinding
will check if there are view_fields.is_for_email_address and if so then loop through to create the unique list of TO, CC, BCC (including CC and BCC using the view_fields.email_address_type)
Exception-Handling
? how could we identify which auto-action is breaking the trigger?
we could have a special “debug-mode” where we create a new duplicate trigger but disable it (so is okay in the production environment)
we loop through all of the actions on the trigger and add only one and see if it executes successfully,
so if there are multiple actions with errors then we will catch all of them instead of just the first one
then we put an alert on the auto-action that it was disabled due to being broken
this alert would be auto-removed once they
action_version_id has to be set before we generate the action but ideally we only create a new action_version rec if the sql output actually changes, so maybe we could have a placeholder for {{action_version_id}}
the zap pseudo-trigger could end up triggering for other recs, so we need a way to pass in the IDs
Also, just calling zap_[table] at the end of each insert/update action can’t work so maybe we instead switch to a generic proc, like “zap_table” where we pass in the table/rec_id so it’s very scoped
Loop through the @t, should pull the exec_date to make sure that still valid zap_[db_table]
Setup Transactions for the trigger-History part?
for the zap_[table] part
so that if its called twice accidentally then won’t duplicate
? What about cascading-trigger ?
In the insert/update (zap) procs we have to call the zap_[table] right after the update
(or at the end of the of the zap_[table], so its recursive but shouldn’t need to be run more than once and can keep track of recursive level in there)
Use the “is_delayed_exec”
when we initially call the trigger then is_delayed_exec=1
have to wait until the zap is called manually
at the end of all the records being saved
for View_Mods
then if there are any inserts/updates from the triggers, we want them to fire right away
But to know whether its being executed from the trigger, we need to have a universal-column (on all tables) that is set to last_mod_user_id - 0 (or -1) to mark it as being modified by a trigger
isSelectFromViewTables
for getting the values from other tables
? Can a zap_[action.id] proc have multiple tables that we are updating or inserting?
No, so whatever the rec_id passed in to the zap is for the action.table_id
Which is based on the “view.table_id”
zap_[db_table]
is_delayed_exec
so call this proc from RecSaver if no view_id
or from the end of view_mods
if its not a sub-form
since should only be called from a parent-form as built-in functionality
Setup the Test for the actions
see use-cases
last_updated_user_id (or last_mod_id) - universal field on all tables for the auto-action triggers to use?
So RecSaver appends it to all tables
p_table_setup always adds it
? or do we just do the extra query for the mod-mains ?
? maybe also last_updated_datetime ? - which is a bit redundant to mod-mains but we could keep these fields hidden
would be super-helpful from a troubleshooting standpoint
use the same “@mod_id” for all of the triggers
? use a universal “last_mod_id” which exists on all of the tables
so all of the triggers would be part of the same mod rec
where in the actions do we specify the “contact_type_id”
how do we get the “triggered_by”
p_field_edit -
Drop and re-create the index when redoing the field types:
alter table [cases] alter column [case_type_id] int null
re-run the “cases” data sql
Setup Scheduled Task for DB Backup
why is “case_closed_date” being included in the trigger when it doesn’t have the “is_action_trigger”
Separate mod_mains setups for each of the checklist sections and items, or just have a timestamp field (or last_mod_id) for troubleshooting
wrapping the procs with a try/catch and entering the errors into the action_history?
the zap_[id] proc wasn’t generated (for zap_4)
nor for the table
select distinct so.name/*, sc.text*/ from sysobjects so inner join syscomments sc on so.id = sc.id where so.name like 'zap%' order by