rules icon indicating copy to clipboard operation
rules copied to clipboard

how to transfer a event/fact in tflowchart

Open brealisty opened this issue 5 years ago • 1 comments

as the demo code: ` with flowchart('expense'): with stage('input'): to('request').when_all(c.first<<(m.subject == 'approve') & (m.amount <= 1000)) to('deny').when_all(c.first<<(m.subject == 'approve') & (m.amount > 1000))

with stage('request'):
    @run
    def request(c):
        print('requesting approve')


    to('approve').when_all(m.subject == 'approved')
    to('deny').when_all(m.subject == 'denied')
    # reflexive condition: if met, returns to the same stage
    to('request').when_all(m.subject == 'retry')

with stage('approve'):
    @run
    def approved(c):
        print('expense approved')

with stage('deny'):
    @run
    def denied(c):
        print('expense denied')

post('expense', {'subject': 'approve', 'amount': 100}) post('expense', {'subject': 'retry'}) post('expense', {'subject': 'approved'})

post('expense', {'sid': 1, 'subject': 'approve', 'amount': 100}) post('expense', {'sid': 1, 'subject': 'denied'})

post('expense', {'sid': 2, 'subject': 'approve', 'amount': 10000}) `

I want transfer first event's value to "approve" stage, so I add "c.first" in line 3 and 4. "request" stage can get the value about first events, but I have no idea how to thransfer this value and to the next stage("approved"). I have tried lots of methods, but not work, even decalre a outer variable.

brealisty avatar Jul 10 '20 08:07 brealisty

Hi, thanks for asking the question. Inside the @run function of the 'approve' stage you can access the event that triggered the transition:

    with stage('approve'):
        @run
        def approved(c):
            print('expense approved {0}'.format(c.first.amount))

jruizgit avatar Sep 08 '20 02:09 jruizgit