How to forward records Randomly

state = fields.Selection(
            ('screening', 'Screening'),
            ('forward_to_baseline', 'Baseline'),
            ('forward_to_screening_failure', 'Screening Failure'),
            ('intervention_arm', 'Intervention Arm'),
            ('control_arm', 'Control Arm')
        ], 'Status', readonly=True, sort=False)

    def __setup__(cls):
        cls._transitions |= set((
            ('screening', 'forward_to_baseline'),
            ('screening', 'forward_to_screening_failure'),
            ('forward_to_baseline', 'control_arm'),
            ('forward_to_baseline', 'intervention_arm'),


            'forward_to_baseline': {
                'invisible': ~Eval('state').in_(['screening']),
                'readonly': (
                    (Eval('have_you_had_t1dm_year_more') != 'yes') |
                    (Eval('your_age_between') != 'yes'
                     ) | (Eval('visit_your_paediatric_healthcare') != 'yes'
                          ) | (Eval('are_you_resident_delhi_ncr') != 'yes') |
                    (Eval('moveout_delhi_ncr_next') != 'no'
                     ) | (Eval('pregnant_or_you_toget_pregnantin_next') != 'no'
                          )), 'depends': ['state'],
            'forward_to_screening_failure': {
                'invisible': ~Eval('state').in_(['screening']),
                'readonly': (
                    (Eval('have_you_had_t1dm_year_more') != 'no') &
                    (Eval('your_age_between') != 'no'
                     ) & (Eval('visit_your_paediatric_healthcare') != 'no'
                          ) & (Eval('are_you_resident_delhi_ncr') != 'no') &
                    (Eval('moveout_delhi_ncr_next') != 'yes') & (Eval(
                        'pregnant_or_you_toget_pregnantin_next') != 'yes')),
                'depends': ['state'],
            'randomization': {
                'invisible': ~Eval('state').in_(['forward_to_baseline']),
                'depends': ['state'],

    def default_state():
        return 'screening'

    @Workflow.transition((random.choice(['control_arm', 'intervention_arm'])))
    def randomization(cls, records):

In above code i have done the code to randomly send records to ‘control_arm’ and ‘intervention_arm’ using random.choice(), but on executing the code record is going in ‘control_arm’ only not in ‘intervention_arm’.
How can I resolve this issue. Any reference to this code will be highly appreciable!!!

This evaluated only once at import. You must put your random choice inside a method to be executed at runtime.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.