I have a content type (plan) which has a 'duration'(provided by this module).

I try to create a rule which would load a plan node, the logged in user and 'apply' the plan to the user.
The user has a 'valid until' date field and application of a plan consists of incrementing the 'valid until' date by the interval specified by 'duration'.

However, the interval field does not seem to support tokens. and hence am unable to use it in rules.

Comments

alansaviolobo’s picture

Here is the rule as it is currently. I need to fetch the interval from the node 'applied_plan' and increment the field from 'recipient_user'

{ "rules_apply_a_plan_to_a_user" : {
    "LABEL" : "Apply a plan to a user",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "recipient_user" : { "label" : "Recipient User", "type" : "user" },
      "applied_plan" : { "label" : "Applied Plan", "type" : "node" }
    },
    "ACTION SET" : [
      { "user_add_role" : {
          "account" : [ "recipient-user" ],
          "roles" : { "value" : { "3" : "3" } }
        }
      },
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "user_subscription_record",
            "param_title" : "[applied-plan:title] plan applied to [recipient-user:name]",
            "param_author" : [ "site:current-user" ]
          },
          "PROVIDE" : { "entity_created" : { "plan_log" : "Plan log entry" } }
        }
      },
      { "data_set" : { "data" : [ "plan-log:field-user" ], "value" : [ "recipient-user" ] } },
      { "data_set" : { "data" : [ "plan-log:field-node" ], "value" : [ "applied-plan" ] } },
      { "entity_save" : { "data" : [ "plan-log" ] } }
    ]
  }
}
larowlan’s picture

Status: Active » Closed (works as designed)

The module provides a rules action called 'apply interval'. Please use that. It is used by commerce recurring.

alansaviolobo’s picture

Hi larowlan,

Thank you for the suggestion. I did find that option. However, on trying to use it, I couldnt get the desired field in the data selector.
I noticed that other than 'body' none of the cck fields were showing up under the node attributes. could that be due to the fact that the content type of the parameter node is not specified anywhere ?

larowlan’s picture

Add a bundle (node type) condition first and the fields should show.