Rules to remind the creator of a case of the case using a date stored in the node using a date field.

Three rules:
1. A rule that sends a mail to the owner of a node
2. A rule that schedules rule 1 after creating a node of a certain type (case) based on a date field of the node.
3. A rule that schedules rule 1 (and overrides the rule scheduled by rule 2) after updating an existing node.

These rules assume that you are using open atrium and have added a new date field to the case content-type called 'duedate' but can be easily adjusted to schedule any node type with a cck date field in a normal drupal 6 distribution.

array (
  'rules' => 
  array (
    'rules_7' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_node_insert',
      '#label' => 'Schedule reminder by date field',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#type' => 'condition',
          '#settings' => 
          array (
            'type' => 
            array (
              'casetracker_basic_case' => 'casetracker_basic_case',
            ),
            '#argument map' => 
            array (
              'node' => 'node',
            ),
          ),
          '#name' => 'rules_condition_content_is_type',
          '#info' => 
          array (
            'label' => 'Created content is Case',
            'arguments' => 
            array (
              'node' => 
              array (
                'type' => 'node',
                'label' => 'Content',
              ),
            ),
            'module' => 'Node',
          ),
          '#weight' => 0,
        ),
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'arguments' => 
            array (
              'task_identifier' => 
              array (
                'type' => 'string',
                'label' => 'Identifier',
                'description' => 'User provided string to identify the task. Existing tasks for this rule set with the same identifier will be replaced',
              ),
              'task_date' => 
              array (
                'type' => 'date',
                'label' => 'Scheduled evaluation date',
              ),
              'user1' => 
              array (
                'label' => 'user1',
                'type' => 'user',
              ),
              'content1' => 
              array (
                'label' => 'content1',
                'type' => 'node',
              ),
            ),
            'label' => 'Schedule Send mail {rule set}',
            'status' => 'custom',
            'categories' => 
            array (
            ),
            'module' => 'Rule Scheduler',
            'base' => 'rules_scheduler_action',
            'set' => 'rules_send_mail',
          ),
          '#name' => 'rules_action_schedule_set_rules_send_mail',
          '#settings' => 
          array (
            'task_identifier' => 'node [node:nid]',
            'task_date' => '[node:field_duedate-datetime]',
            '#argument map' => 
            array (
              'user1' => 'author',
              'content1' => 'node',
            ),
            '#eval input' => 
            array (
              'token_rules_input_evaluator' => 
              array (
                'task_identifier' => 
                array (
                  0 => 'node',
                ),
                'task_date' => 
                array (
                  0 => 'node',
                ),
              ),
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
    'rules_8' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_node_update',
      '#label' => 'Schedule reminder by date field',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#type' => 'condition',
          '#settings' => 
          array (
            'type' => 
            array (
              'casetracker_basic_case' => 'casetracker_basic_case',
            ),
            '#argument map' => 
            array (
              'node' => 'node',
            ),
          ),
          '#name' => 'rules_condition_content_is_type',
          '#info' => 
          array (
            'label' => 'Created content is Case',
            'arguments' => 
            array (
              'node' => 
              array (
                'type' => 'node',
                'label' => 'Content',
              ),
            ),
            'module' => 'Node',
          ),
          '#weight' => 0,
        ),
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'arguments' => 
            array (
              'task_identifier' => 
              array (
                'type' => 'string',
                'label' => 'Identifier',
                'description' => 'User provided string to identify the task. Existing tasks for this rule set with the same identifier will be replaced',
              ),
              'task_date' => 
              array (
                'type' => 'date',
                'label' => 'Scheduled evaluation date',
              ),
              'user1' => 
              array (
                'label' => 'user1',
                'type' => 'user',
              ),
              'content1' => 
              array (
                'label' => 'content1',
                'type' => 'node',
              ),
            ),
            'label' => 'Schedule Send mail {rule set}',
            'status' => 'custom',
            'categories' => 
            array (
            ),
            'module' => 'Rule Scheduler',
            'base' => 'rules_scheduler_action',
            'set' => 'rules_send_mail',
          ),
          '#name' => 'rules_action_schedule_set_rules_send_mail',
          '#settings' => 
          array (
            'task_identifier' => 'node [node:nid]',
            'task_date' => '[node:field_duedate-datetime]',
            '#argument map' => 
            array (
              'user1' => 'author',
              'content1' => 'node',
            ),
            '#eval input' => 
            array (
              'token_rules_input_evaluator' => 
              array (
                'task_identifier' => 
                array (
                  0 => 'node',
                ),
                'task_date' => 
                array (
                  0 => 'node',
                ),
              ),
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
    'rules_6' => 
    array (
      '#type' => 'rule',
      '#set' => 'rules_send_mail',
      '#label' => 'Send mail {rule}',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'label' => 'Send a mail to a user',
            'arguments' => 
            array (
              'user' => 
              array (
                'type' => 'user',
                'label' => 'Recipient',
              ),
            ),
            'module' => 'System',
            'eval input' => 
            array (
              0 => 'subject',
              1 => 'message',
              2 => 'from',
            ),
          ),
          '#name' => 'rules_action_mail_to_user',
          '#settings' => 
          array (
            'from' => '',
            'subject' => 'je taak gedaan?',
            'message' => '<p>&nbsp;<span class="Apple-style-span" style="white-space: pre; ">je taak gedaan?</span></p>',
            '#argument map' => 
            array (
              'user' => 'user1',
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
  ),
  'rule_sets' => 
  array (
    'rules_send_mail' => 
    array (
      'arguments' => 
      array (
        'user1' => 
        array (
          'label' => 'user1',
          'type' => 'user',
        ),
        'content1' => 
        array (
          'label' => 'content1',
          'type' => 'node',
        ),
      ),
      'label' => 'Send mail {rule set}',
      'status' => 'custom',
      'categories' => 
      array (
      ),
    ),
  ),
)

Comments

pbillon’s picture

Great rules, this is exactly what I needed. However it seems that the reminder is sent to the Author only. Is there a way to set it up so that the reminder is sent to the case assignee? I tried replacing 'author' by the token for the casetracker assignee but couldn't find that token and don't know if it will be recognize by rules.

If this is not possible, I was thinking replacing 'author' with a token [node:filed_assignee] and create a new field for casetracker named assignee. But I do not want athors of the case to have to fill the assignee filed themselves. I would like to find a way so that the assignee field be filled with the value of the Case:Assign to. Does any one knows how to do that.

I'm sure that I am not the only one who would like to able to send the reminder to the case assignee... anyone found the solution?

Thanks.

Andrés Chandía’s picture

Could you explain please, for newbies, where the code should be pasted for this to work.

Thanks

@ch

mdallmeyer’s picture

This is the exported code for the rules, so to use it, you just want to go to /admin/rules/ie/import and paste away.
I too, am looking to customized this segment so that it sends an email to an address stored in a field, I will let you know my results.

mdallmeyer’s picture

I used this patch to get CCK User Reference fields to accept the [user-mail] token. Below is my exported rules which send the email to the address of the user in [content1:field_some_user_reference_field], which you can of course change to match your field machine name. I realize there is some redundancy in that 'user1' and 'content1' are doing the same job, but I'm too lazy to go through and remove one.

Hope this helps, let me know if you have questions!

array (
  'rules' => 
  array (
    'rules_7' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_node_insert',
      '#label' => 'Schedule reminder by date field',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#type' => 'condition',
          '#settings' => 
          array (
            'type' => 
            array (
              'casetracker_basic_case' => 'casetracker_basic_case',
            ),
            '#argument map' => 
            array (
              'node' => 'node',
            ),
          ),
          '#name' => 'rules_condition_content_is_type',
          '#info' => 
          array (
            'label' => 'Created content is Case',
            'arguments' => 
            array (
              'node' => 
              array (
                'type' => 'node',
                'label' => 'Content',
              ),
            ),
            'module' => 'Node',
          ),
          '#weight' => 0,
        ),
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'arguments' => 
            array (
              'task_identifier' => 
              array (
                'type' => 'string',
                'label' => 'Identifier',
                'description' => 'User provided string to identify the task. Existing tasks for this rule set with the same identifier will be replaced',
              ),
              'task_date' => 
              array (
                'type' => 'date',
                'label' => 'Scheduled evaluation date',
              ),
              'user1' => 
              array (
                'label' => 'user1',
                'type' => 'node',
              ),
              'content1' => 
              array (
                'label' => 'content1',
                'type' => 'node',
              ),
            ),
            'label' => 'Schedule Send mail {rule set}',
            'status' => 'custom',
            'categories' => 
            array (
            ),
            'module' => 'Rule Scheduler',
            'base' => 'rules_scheduler_action',
            'set' => 'rules_send_mail',
          ),
          '#name' => 'rules_action_schedule_set_rules_send_mail',
          '#settings' => 
          array (
            'task_identifier' => 'node [node:nid]',
            'task_date' => '[node:field_duedate-datetime]',
            '#argument map' => 
            array (
              'user1' => 'node',
              'content1' => 'node',
            ),
            '#eval input' => 
            array (
              'token_rules_input_evaluator' => 
              array (
                'task_identifier' => 
                array (
                  0 => 'node',
                ),
                'task_date' => 
                array (
                  0 => 'node',
                ),
              ),
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
    'rules_8' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_node_update',
      '#label' => 'Schedule reminder by date field',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#type' => 'condition',
          '#settings' => 
          array (
            'type' => 
            array (
              'casetracker_basic_case' => 'casetracker_basic_case',
            ),
            '#argument map' => 
            array (
              'node' => 'node',
            ),
          ),
          '#name' => 'rules_condition_content_is_type',
          '#info' => 
          array (
            'label' => 'Created content is Case',
            'arguments' => 
            array (
              'node' => 
              array (
                'type' => 'node',
                'label' => 'Content',
              ),
            ),
            'module' => 'Node',
          ),
          '#weight' => 0,
        ),
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'arguments' => 
            array (
              'task_identifier' => 
              array (
                'type' => 'string',
                'label' => 'Identifier',
                'description' => 'User provided string to identify the task. Existing tasks for this rule set with the same identifier will be replaced',
              ),
              'task_date' => 
              array (
                'type' => 'date',
                'label' => 'Scheduled evaluation date',
              ),
              'user1' => 
              array (
                'label' => 'user1',
                'type' => 'node',
              ),
              'content1' => 
              array (
                'label' => 'content1',
                'type' => 'node',
              ),
            ),
            'label' => 'Schedule Send mail {rule set}',
            'status' => 'custom',
            'categories' => 
            array (
            ),
            'module' => 'Rule Scheduler',
            'base' => 'rules_scheduler_action',
            'set' => 'rules_send_mail',
          ),
          '#name' => 'rules_action_schedule_set_rules_send_mail',
          '#settings' => 
          array (
            'task_identifier' => 'node [node:nid]',
            'task_date' => '[node:field_duedate-datetime]',
            '#argument map' => 
            array (
              'user1' => 'node',
              'content1' => 'node',
            ),
            '#eval input' => 
            array (
              'token_rules_input_evaluator' => 
              array (
                'task_identifier' => 
                array (
                  0 => 'node',
                ),
                'task_date' => 
                array (
                  0 => 'node',
                ),
              ),
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
    'rules_6' => 
    array (
      '#type' => 'rule',
      '#set' => 'rules_send_mail',
      '#label' => 'Send mail {rule}',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'label' => 'Send a mail to a user',

            'module' => 'System',
            'eval input' => 
            array (
              0 => 'subject',
              1 => 'message',
              2 => 'from',
			  3 => 'to',
            ),
          ),
          '#name' => 'rules_action_mail',
          '#settings' => 
          array (
			'to' => '[content1:field_some_user_reference_field-mail]',
            'from' => 'DoNotReply@yoursite',
            'subject' => 'Reminder: [content1:title] due on [content1:field_duedate-date]!',
            'message' => 'Dear [content1:field_some_user_reference_field-name],
This is a reminder that [content1:title] is due [content1:field_duedate-datetime].
This node can be reached at [content1:node-url]',
            '#eval input' => 
            array (
              'rules_input_evaluator_php' => 
              array (
                'to' => 
                array (
                  0 => 'user1',
                  1 => 'content1',
                ),
		'subject' => 
                array (
                  0 => 'user1',
                  1 => 'content1',
                ),
                'message' => 
                array (
                  0 => 'user1',
                  1 => 'content1',
                ),
              ),
              'token_rules_input_evaluator' => 
              array (
                'to' => 
                array (
                  0 => 'user1',
                  1 => 'content1',
                ),
		'subject' => 
                array (
                  0 => 'user1',
                  1 => 'content1',
                ),
                'message' => 
                array (
                  0 => 'user1',
                  1 => 'content1',
                ),
	      ),
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
  ),
  'rule_sets' => 
  array (
    'rules_send_mail' => 
    array (
      'arguments' => 
      array (
        'user1' => 
        array (
          'label' => 'user1',
          'type' => 'node',
        ),
        'content1' => 
        array (
          'label' => 'content1',
          'type' => 'node',
        ),
      ),
      'label' => 'Send mail {rule set}',
      'status' => 'custom',
      'categories' => 
      array (
      ),
    ),
  ),
)
mdallmeyer’s picture

I'm trying to do basically this same thing, but I would like a little more customization when it comes to the message that gets sent out. I'd like to give some information on which case the reminder is for, so I've tried a few different ways to get the "Send mail" rule to have access to the node being referenced from the other rules but I've had no luck.

The only arguments passable for rules_action_mail_to_user are 'user' and 'settings'. Would it be possible to create the 'settings' array from the other rules and pass that along? Say for example I want the emails 'from' field to be derived from a field like [node:field_assigned_by] which is a dropdown list of users. And maybe the message would have a link to the node itself.

Thanks for any help!