I am receiving this error when a reaction rule tries to change a workflow state triggered by anyone other than an administrator:

Workflow cannot be loaded. Contact your system administrator.
Wrong call to constructor Workflow*Transition(0 to 13)
You tried to set a Workflow State, but the entity is not relevant. Please contact your system administrator.

I have checked and re-checked the permissions. However, shouldn't the rule change the workflow state regardless of the permissions of the user? One of the first times this appeared was with an entity form saved by an anonymous user triggering a rule, and I figured it was the fact that it was triggered by an anonymous user... but it is actually happening for all my rules triggered on an entity other than the actual workflow entity with the field.

This seems related to other issues concerning permissions and rules, but i'm not sure.

For the record, I'm using Workflow field. This was working perfectly in the same site when I was using Workflow Node. I had to re-do all my rules to workflow field because of some other issues I had with related upgrades.

Comments

tchopshop’s picture

Status: Active » Closed (works as designed)

I'm closing this issue because I realized that it WILL work with the generic rule "Set a data value" on the workflow field. I was using the "Set a Workflow Field State" which does not work in any of my rules. That rule should be removed it's very deceptive.

johnv’s picture

Status: Closed (works as designed) » Active

Ok, i will keep it open then.

johnv’s picture

Title: Workflow cannot be loaded. » Error "Workflow cannot be loaded." when using Rules Action "Set a Workflow Field State"
Component: Code » Rules
johnv’s picture

Status: Active » Fixed

Indeed, the Rules Action "Set a Workflow Field State" is not needed for Workflow Field. It is there because some people might be using it.
The following fix adds some text to the Action description, telling you to use the 'Set a data value' action.

  • johnv committed 12da947 on 7.x-2.x
    Issue #2323025: Deprecated Rules Action 'Set a Workflow Field State'.
    
johnv’s picture

Status: Fixed » Active

My comment #4 is not true. The default action 'Set a data value'only changes the value of the Workflow State. The action 'Set a Workflow State' also allows you to set a Comment.

( P.S. It should even be possibe to schedule a sstate change via rules.)

  • johnv committed 1cb7734 on 7.x-2.x
    Issue #2323025: Reverted deprecation of Rules Action 'Set a Workflow...
tchopshop’s picture

I don't understand. So if you're saying it's working why didn't any of my rules work with that action?

This has been a very frustrating journey. I had workflow node working in my site, then because of updates and errors I had to convert everything to workflow field. Then I set all my rules with "set a workflow state" and that did not work, so I had to return and change all of them to "Set a data value". I wish it was clear what was the proper path, it would have saved me weeks of work.

  • johnv committed 8d80f2b on 7.x-2.x
    Issue #2323025: Reverted deprecation of Rules Action 'Set a Workflow...

  • johnv committed 99c86b0 on 7.x-2.x
    Issue #2323025: Reverted deprecation of Rules Action 'Set a Workflow...
johnv’s picture

I am sorry for the headaches this caused you. I'm not saying that it is working - i'm saying, that it is a valid action that should work.

I did an extensive test with todays -dev version, using this rule, with a 'normal' user. The test-rule sets the node to a value that is not possible according to the Transitions settings (so, Rules overrides the configured transitions). This is the current status:
- Workflow Field: 'After updating existing content', 'Set a Workflow state...' --> OK
- Workflow Node: 'Workflow state has changed', 'Set a Workflow state...' --> OK (but you need to refresh the page)
- Workflow Field: After saving a term, set a Workflow state --> OK
- Workflow Node: After saving a term, set a Workflow state --> Not Possible --> OK

But returning to your original post:
"... but it is actually happening for all my rules triggered on an entity other than the actual workflow entity with the field."
This means you have a flag, field_collection - or other entity - with a workflow, that should change the state of a third entity?
Can you post an export of the rule?

In general, the last months, several people have mentioned they are using entityforms. I never did. Can you explain you use case?

Also, there are some issues when using third-entities: #2074859: Views displaying wrong data when using references/revisions/multiple fields

  • johnv committed ea339c3 on 7.x-2.x
    Issue #2323025: Updated Rules Action 'Set a Workflow Field State'.
    
johnv’s picture

Above commit is just to make sure we both have the same state of code.
I updated comment #11.

tchopshop’s picture

Yes, indeed. That's the issue.

I have a byzantine workflow for Candidates to fulfill requirements and get voted on to achieving Fellowship in an honorary organization. The workflow is on the Candidate node. The other entities are either referencing that node or they are flags on the Candidate node. Once an Entity form is filled out by an anonymous visitor with a reference to this candidate, then the workflow changes state and voting is allowed, then some (sponsor letter) nodes are created that reference the candidate, then more people vote and on and one each thing progresses changing the workflow field.

It didn't work when triggered by saving an entity, flag or other node (not 100% sure about this last one). The rule would be After saving a new entity form submission, or a node has been flagged, or after saving new content of type sponsor letter.

Here's the export of one (but this is after changing it to Set a Data Value):
{ "rules_change_workflow_cif_submitted_complete" : {
"LABEL" : "Change Workflow -- CIF submitted, complete",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",df

LCM’s picture

Hi,

I am having issues with the mentioned process of transitioning into another state via rules, that is not available for the user saving an entity (node).

Since fixing WorkflowState::getTransitions() the mentioned way of changing a workflow state (workflow field in use here) through rules, that is otherwise not allowed for the current user, will not. I _guess_ this might be related to the fact, that without the mentioned fix in getTransitions, any user would receive the "Author" Role in any case.

I tracked the issue down to the way, the entity is saved via rules (field_attach_update) and the missing workflowfield_entity_insert/update calls to module_invoke_all('transition post'). Given your mentioned context:

I have a workflow field on a content type and a rule that will transition to a state via "Set a workflow state (with comment)" on "After updating existing content". The transition is not allowed for the current user and the result is the following (in this Order!)

The rule is triggered transitioning setting the state and creating a comment. OK

The entity should be saved triggering a transition from the original state to the new state failing since this is done without _force_.

I end up with a Workflow Comment in History that the state transition worked, but the entity still has the old state value in the workflow field.

Can you shed some light on why the mentioned hooks for entity_update/insert are not yet implemented? I could help, as we need this working!

Regards,

Lennart

  • johnv committed 096b947 on 7.x-2.x
    Issue #2323025: Fixed Rules Action 'Set a Workflow Field State' does not...
johnv’s picture

Status: Active » Fixed

@LCM, I could reproduce your problem. It should be fixed with adjacent commit.
In general the code struggles already for years with this scenario: "use changes state; program makes follow-up change.".
In the current version, the state change via Rules does not have to be an existing Transition. The parameter $force=TRUE makes sure some checks are skipped.

For reference, I'm testing with below Rule:

{ "rules_node_state_change_" : {
    "LABEL" : "node state change ",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "workflow_rules" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_workflow" } },
      { "data_is" : { "data" : [ "node:field-workflow" ], "value" : "27" } }
    ],
    "DO" : [
      { "workflowfield_field_set_state" : {
          "node" : [ "node" ],
          "field" : [ "node:field-workflow" ],
          "workflow_state" : { "value" : { "62" : "62" } },
          "workflow_comment" : "via Rules "
        }
      }
    ]
  }
}

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.