To create and try a Python code server action, follow these steps:
- Create a new server action: on the Settings top menu, select the Technical | Actions | Server Actions menu item, and click on the Create button at the top
of the record list. - Fill out the Server Action form with the following values:
- Action Name: Send Reminder
- Base Model: Task
- Action To Do: Execute Python Code
- In the Python code text area, remove the default text and replace it with the following:
if not record.date_deadline: raise Warning('Task has no deadline!') deadline_dt = datetime.datetime.strptime( obj.date_deadline, '%Y-%m-%d') delta = deadline_dt.date() - datetime.date.today() days = delta.days if days==0: msg = 'Task is due today.' elif days < 0: msg = 'Task is %d day(s) late.' % abs(days) else: msg = 'Task will be due in %d day(s).' % days record.message_post(msg, subject='Reminder', subtype='mt_comment')
- Save the Server Action and click on Add in the 'More' Button at the top-right to make it available in the Project task's More button.
- Now, click on the Project top menu and select the Search | Tasks menu item. Pick a random task, set a deadline date on it, and then try the Send Reminder option in the More button.