1

I need to email owner when task is assigned to them. I tried following ways:

  1. Assign accepts a callable function which should return task owner. We can send email in this callable function. But if you read source code, you will find that this callable method is called multiple times, by calc_owner function. Hence if we email user here, multiple emails will be send

  2. Create a new Node method like EmailUser and call it after Assign and before Next. But the issue is, it should also be thorough some callable like Assign for it to be called for each Process. But where to call this callable function

This seems like very general use-case, with a very difficult solution. Or am I missing something?

Sid
  • 589
  • 6
  • 20

1 Answers1

1

This functionality could be achieved in a custom subclass of flow.View, with custom activation class, where you can extend create_task method:

https://github.com/viewflow/viewflow/blob/master/viewflow/flow/activation.py#L77

approve = (
    UserTask(view.MyView)
    .onCreateEmail(template='...', recipients=....)
    .onAutoAssignEmail(template='...')

)

kmmbvnr
  • 5,863
  • 4
  • 35
  • 44
  • How does the `onCreateEmail` reference to the same user that gets randomly chosen using `Assign(lambda act: random(user))`? – James Lin Oct 29 '19 at 01:36
  • OK I worked it out by overwriting the `calc_owner` to add extra code to send out the email. – James Lin Oct 29 '19 at 08:02
  • The correct way is to implement custom activation class with overridden activate method. Flow class node stands for declarative node definition only – kmmbvnr Oct 31 '19 at 10:37