I have nodes with workflow field which I need to update using cron from one state to another state. I built a VBO view and tried to use that list as source to which nodes to update. I do not seem to have a way to choose workflow field in Rules at all.

Exported rule below here is not saveable, since "entity-fetched:field-myworkflow" is not exposed at all. Node author (entity-fetched:author) does have fields, but top-level entity does not.

{ "rules_update_wf_state" : {
    "LABEL" : "Update Workflow State",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "views_bulk_operations", "rules", "workflow_rules" ],
    "ON" : { "cron" : [] },
    "IF" : [
      { "views_bulk_operations_condition_result_count" : { "view" : "nodes_for_rules_cron|default", "minimum" : "1" } }
    ],
    "DO" : [
      { "views_bulk_operations_action_load_list" : {
          "USING" : { "view" : "nodes_for_rules_cron|default" },
          "PROVIDE" : { "entity_list" : { "entity_node_list" : "A list of entity objects" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "entity-node-list" ] },
          "ITEM" : { "list_item_node" : "Current node" },
          "DO" : [
            { "entity_fetch" : {
                "USING" : {
                  "type" : "node",
                  "id" : [ "list-item-node:nid" ],
                  "revision_id" : [ "list-item-node:vid" ]
                },
                "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
              }
            },
            { "workflowfield_field_set_state" : {
                "node" : [ "entity-fetched" ],
                "field" : [ "entity-fetched:field-myworkflow" ],
                "workflow_state" : { "value" : { "4" : "4" } },
                "workflow_comment" : "Automatically updated state."
              }
            }
          ]
        }
      }
    ]
  }
}

Comments

rpsu’s picture

I tried to solve this also with custom Rules action (in a custom module), but can't figure out how to simply update workflow field. That would help me go around problem at this point.

johnv’s picture

I am confused: it seems you need a vbo view to schedule state transitions. That is perfectly possible with the latest version ( there were some problems with this vbo action, but they should be solved.) With that vbo view, you do not need to use an extra Rules thingy.

Please just try to set a scheduled state with VBO. Cron will execute the state change when time comes. If it is not working , it will be fixed.
See also #2189761: How to use Rules support for Workflow Field

rpsu’s picture

Thanks @johnv, but I do not seem to get this working.

My use case is that I need to bulk-update (or programmatically schedule) a state change based on another date field value. I though this would be the easiest thing to do with Views list and loop through items returned by this view but I am apparently wrong.

For example:

  1. a node in "to-be-checked" state is updated to "checked" -state with a date field set in distant future
  2. a week before node's date field value it needs to be set to "locked" state
  • either: use cron to update node wf field state; use a view to get nodes and in Rules action loop throug nodes and change wf field state?
  • or: shedule a state change with Rules to be executed at a spesific date to avoid forcing user to choose when this should happen

I do not find a way to expose workflow field value in Rules to set workflow field value.

Could you please be more spesific how this in your opinion should be done?

rpsu’s picture

Component: Views VBO » Views

I was probably lost using VBO part, sorry for misleading.

johnv’s picture

johnv’s picture

johnv’s picture

Title: Using cron-exucuted VBO nodes list to update workflow with Rules not possible? » Using cron-executed VBO nodes list to update workflow with Rules not possible?
rpsu’s picture

Status: Active » Closed (duplicate)

Functionality I am looking for can be achieved also using scheduled workflow transitions, marking this as a duplicate of #2217017: Rules action to check workflow field state and to schedule transition