Page 1 of 1

Script types, before_, instead_, after_

PostPosted: Wed Aug 17, 2016 8:33 pm
by grahamb
Although I can reason when the three classes of triggers; before_, instead_of_ and after_ are applied, it's not clear to me what the practical differences are between the classes.

Presumably there are processes that a best carried out at a particular point, is there any guidance on this?

The kind of things I'm looking at are:

  • Setting the task shortname
  • Validating custom field content
  • Setting task deadline
  • Setting UDF based on hierarchical position
  • Setting the task assignee

I also have similar questions for triggers applied to messages.

Re: Script types, before_, instead_, after_

PostPosted: Mon Aug 22, 2016 5:28 pm
by admin

All 3 kind of scripts are executed when you save task or message. BEFORE executed before save, it's good place to check that all fields correct, modify values. If some value is wrong - just throw UserException("error message").

INSTEAD OF executed instead of save task/message, it's useful if you needn't new message, just like to modify something. For example, you can create message "Like" and increase like counter, but don't create messages in the history.

AFTER scripts are executed after message has been created, it's too late to modify task/message there, such scripts used to do some "post-action", like update info in external system, copy created task to knowledge base, etc.