Skip to main content
Skip table of contents

Jython Events

Die nachfolgenden Inhalte sind nur in englischer Sprache verfügbar.

Data-Driven Events

Method Parameter Return valueComment

some_event(event, pojo)

event: the event itself

pojo: the pojo triggering the event

bool

Example

  • To propagate changes to related records you can use a post-insert/update event
  • In this example we increase a counter on the parent record when inserting a child record:
JAVA
def increase_parent_counter_event(event, pojo):
	parent_uuid = pojo.parent_uuid
	parent_entity = utilities.get_pojo_by_uuid(‘Task’, parent_uuid)
	if parent_entity:
		child_counter = parent_entity.amount_of_children
		parent_entity.amount_of_children += child_counter
		utilities.save_pojo(parent_entity)
	return True
  • We then create an event record for the table which contains the record, set the event type to “post-insert”, function type to “jython”, insert the path to this event function, and enable the “active” flag of the event

Time-Controlled Events

Method Parameter Return valueComment

some_event(event)

event: the event itself

bool

Example

  • You can automate tasks that are carried out at particular times by using timed events
  • In this example we send an email with information on the tasks of a project each day:
JAVA
def send_project_info_event(event):
	project_uuid = event.parameter
	project_entity = utilities.get_pojo_by_uuid(‘Project’, project_uuid)
	if not project_entity:
		return
	open_tasks = utilities.db_select(“select count(*) from Task t where t.pr_id = ‘{project_id}’ and t. actual_end = ’01.01.1970’”.format(project_id=project_entity.pr_id)[0][0]
	project_manager = project_entity.pr_manager
	manager_uuid = utilities.db_select(“select u.id from User u where u.user = ‘{project_manager}’”.format(project_manager=project_manager)[0][0]
	manager_entity = utilities.get_pojo_by_uuid(‘User’, manager_uuid)
	if not manager_entity:
		return
	manager_email = manager_entity.e_mail
	default_sender = utilities.get_global_setting_value(‘default_email_sender’, ‘alpha120’)
	subject = “Info about project {pr_functional}”.format(pr_functional=project_entity.pr_functional)
	message = “There are {open_tasks} open tasks”.format(open_tasks=open_tasks)
	send_email(sender=default_sender, recipient=manager_email, subject=subject, message=message)  # this function doesn’t exist, just a simple wrapper for smtplib.sendmail

  • We then create a timed event record, set a name, set the function type to “jython”, insert the path to this event function, set a parameter if needed (in this case the project uuid), set day, time and interval as required (in this case, day is irrelevant, time is the time at which it should be sent each day and interval is daily) and enable the “active” flag of the event
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.