Hi,

I just had a question in regards to setting truth values using token replacement.

When I add a condition: Check Truth Value, all I want to do is check:

[node:workflow-current-state-name]

token to see which state I am in. There is a text box for a truth value, but how would I go about checking what state I am in.

Lets say, I have news content that is in state "unpublished", how would I assign a Check Truth Value condition that tests to see if:

[node:workflow-current-state-name] = "unpublished" ?

Any help would be greatly appreciated.

Thanks,
Raj

Comments

mrtm3050’s picture

Component: Rules Core » Rules Engine

Just to be completely clear, my triggered rule is for the event:

After Saving New Content

I am trying to send an email out when two conditions are met:

Condition 1: When created contents field 'something' has a value
AND
Condition 2: Check a Truth Value

The second condition is where I am running into problems where I want to check to see what state I am in using tokens. All I see is a truth value box?

If these two conditions are met:

Action: Send Mail to an Arbitrary Address

amitaibu’s picture

Title: Drupal Rules/Conditions/Workflow Question » Truth Conditions with token
Status: Active » Postponed (maintainer needs more info)

Is workflow-current-state-name a cck field? If so you can use the 'Field has value' condition.

mrtm3050’s picture

Title: Truth Conditions with token » Drupal Rules/Conditions/Workflow Question
Status: Postponed (maintainer needs more info) » Active

No, [node:workflow-current-state-name] is a token.

So there is a textual comparison rule that I am using, that basically checks to see if:

[node:workflow-current-state-name] = "my current state name"

However, after turning on the rules debugger, and sending around some tokenized emails, it seems that:

[node:workflow-current-state-name]

has no value. My emails have several other tokens, but [node:workflow-current-state-name] seems to just return an empty string.

Any help would be greatly appreciated.

amitaibu’s picture

Yes, I know it's a token - but who creates this token? Is this a cck-field?

mrtm3050’s picture

I am not sure, I dont know who would create the token. When I set a condition in rules that does a textual comparison, there is a link called "token replacement patterns" followed by a link to "replacement patterns for updated content" where I see all the tokens and their replacement values I assumed was created by the token module. This is where I see a list of tokens such as [node:nid] which seems to work fine, and [node:workflow-current-state-name] which does not.

Currently, I have several fields, namely:

select lists, text and decimal input fields for a new content type I created called "Estimate".

Subsequently, I created a workflow called "Projects" with several states that was assigned to this new content type "Estimate".

I assumed that the workflow/token modules would automatically create the [node:workflow-current-state-name] when I assigned the "Projects" workflow to my content type "Estimate."

Is this something I have to do where I have to set the value of the token? Wouldnt either the token module or workflow module create this token?

I have tested the other tokens such as the [node:nid] and they seem to work fine. I guess my question is, what creates the token [node:nid] that allows that token to function normally that would not also create the token [node:workflow-current-state-name].

I'm probably just missing something obvious, so I would certainly appreciate your help if you have any ideas.

Thanks

mrtm3050’s picture

So I made some progress.

This previous thread holds some insight as to what might be happening: http://drupal.org/node/327144#comment-1338436

It looks like the workflow module has a function called workflow_token that sets the [node:workflow-current-state-name]. However, it seems that this only works on the rule "After updating existing content" and not for "After saving new content", meaning, when I create content mapped to a workflow, the token [node:workflow-current-state-name] is not replaced, but when I update the content, the [node:workflow-current-state-name] does get replaced.

mitchell’s picture

Title: Drupal Rules/Conditions/Workflow Question » Help using Workflow's states with Rules
Status: Active » Postponed (maintainer needs more info)

@mrtm3050: Please help us fill in the gaps so we know how Rules and Workflow can work together.

Since Rules documentation doesn't explicitly say, "Use CCK fields as workflow states," it makes sense that people will install both.

Workflow now has integration with two new modules, that require testing with Rules: Revisioning and Module Grants. Could someone please post their experiences with these modules here?

mitchell’s picture

fago’s picture

I think for supporting revisions revision moderation is a good choice. In 5.x there was already workflow-ng integration that needs to be ported to rules. Also there is http://drupal.org/node/376468.

@workflow:
I think we should also support workflow module with rules, there was workflow-ng support in 5.x.

The "cck way" currently misses a way to log changes, as there is no rules logging module yet.

adshill’s picture

I'm using workflow and rules together (6.x) and with the patch here: http://drupal.org/node/327144 they work well together using the Textual Comparison and the Tokens for workflow state. HOWEVER at this moment there is no way to have a condition that is along the lines of "If workflow has changed" - this presents a fundamental problem which I'm trying to deal with at the moment but my lack of php knowledge doesn't help.

To give an example:

We have a "member" content type which has the workflow: (Creation)/Check/New Application/Approved/Declined. A simple rule set up does a textual comparison to see if state was previously "New Application" and current state is "Approved" then an e-mail is sent to the user. This works when the state is changed from New Application -> Approved and the e-mail is sent. The problem is that if you then edit the member (for example change a field) when you click on save, then it still sends the e-mail notification. Now I understand that logically this makes sense, but it would be perfect to have a "If workflow has changed" condition - that I presume would act just like the "If field has changed" condition. This would result in perfect integration with the modules (as far as I can see).

Unfortunately, I don't have the skills to code this. But if anyone else does I'd be prepared to pay a bounty of $100 if achieved within a day or two... because I'm desperate for this!! :)

Thanks,

Adam

cam_pdx’s picture

I would appreciate it if someone would tell me how to get the "Send a Tokenized Mail" option. I have Rules 6.x-1.0-beta5, Token 6.x-1.11, and Workflow 6.x-1.1 installed. I have disabled Token actions (per the FAQ at http://groups.drupal.org/node/10270/faq#missing-token-module).

When I attempt to add an action to a rule, the only options pertaining to email that I see are:
- Send a mail to a user
- Send a mail to all users of a role
- Send a mail to an arbitrary mail address

I've tried using the Send a mail to a user option with token placeholders listed in the email, but the email comes back to me exactly as written without replacing the tokens with their respective values. For example:
Node:
[nid]
[type]
[type-name]
[title]
[author-uid]
[author-name]
[author-mail]
[node:workflow-old-state-name]
[node:workflow-current-state-name]

The reason I'm trying to do this is to figure out what the values are for [node:workflow-old-state-name] and [node:workflow-current-state-name], because when I try to do a Rules check on a Textual comparison of [node:workflow-current-state-name] to either (creation) or Draft (a workflow state I put in place), it always evals to false.

Thank you for any information!

dooug’s picture

Comment #10:
Adshill, I also have the same issue. I've yet to find a solution

Comment #11:
If the tokens are not being replaced, you probably need to install the development snapshot of the Tokens module. This is noted on the Rules project page http://drupal.org/project/rules.

Installation notes
To get token replacements in your actions, install the latest development snapshot of token! You need a snapshot which stems from >27.08.08

adshill’s picture

Hi dooug,

I found the solution in the end through a bit of advice and some playing, and it's actually quite simple. All you need to do is set up a negated condition so that the rule only happens if the CURRENT STATE in the saved content is NOT equal to the CURRENT STATE in the unsaved content. This way it will only process if the state is actually changed on that occassion. Sorry for not posting that here earlier and sorry to fago for not replying to your PM, I've just been completely swamped in a development.

Let me know if that works or if you have any problems. Best,

Adam

Alpha5’s picture

There is a performance here when use that way than have a workflow state change event. You still need an event to check a rule, it may be "After updating exitsting content"..., so if you just save post but not change state, this event occur and rule will need to check condition.

I get this when I use view with editablefield in some field, it save post every time I add a value.

And as I know, token get value after rule excute, so the token [node:workflow-current-state-name] not get true value if use in rules.

globalvillage’s picture

I had this issue too, fixed it by using "Check a Textual Value" rather than "check a truth value" comparison.

chalee’s picture

adshill

The solution you gave here is unfortunately not working for me. The Updated Content and Unchanged Content tokens are giving me the same values: I have states: submitted, cancelled, approved etc. When I move from submitted to cancelled, here are the token values I get:

Updated Content
[node:workflow-current-state-name] : submitted
[node:workflow-old-state-name]: cancelled

Unchanged document
[node_unchanged:workflow-current-state-name]: submitted
[node_unchanged:workflow-old-state-name]: cancelled

As a result I can't use the tokens to test if a workflow state has changed. Can anyone assist?

P/S:
To add more information I'm using the following versions:

Rules 6.x-1.0
Workflow 6.x-1.x-dev
Workflow Fileds 6.x-1.x-dev

I'm writing the rule condition and action on event "After updating existing content" I will be glad to provide additional specific information if necessary to solve this issue.

chalee’s picture

Status: Postponed (maintainer needs more info) » Active

I added more info to my previous post

wickwood’s picture

Hello Mitchell,

I have been working integrating Rules, Workflows, Revisioning and Module Grants and you can see the status of my latest work here:
http://drupal.org/node/493246#comment-1744306

Hope you find it helpful and if you have any insights I would appreciate hearing them.

Steve

adshill’s picture

Chalee,

Did you try the patch mentioned in my post? http://drupal.org/node/327144

Let me know if that helps... if not then in what you've provided I'm not sure why you're getting the same token values. Does the same occur between other states? As I don't currently use workflow fields I don't know if/how this could affect things - maybe you could disable it and test again to see if it makes any difference?

Let me know how you get on and I'll do my best to respond. Good luck.

Thanks,

Adam

adshill’s picture

Also what version of tokens are you using? See Comment #12.

fivehimself’s picture

I'm also trying to accomplish pretty much the same.

I have a lot of different states in Workflow and based on these states I want the node to publish or set it to unpublished.

I think I have to make 2 scenarios: one for newly created content, and one for updated / changed content.

But I can't get the validation on workflow states accurate, even when it doesn't validates it executes the action.

My condition is a textual comparison:
Negate, [node_unchanged:workflow-current-state-name], [node_unchanged:workflow-old-state-name]

But this outputs:

0.761 ms Executing the rule Workflow publish - Updating content on rule set After updating existing content
2.808 ms Condition Textual comparison evaluated to FALSE.
2.941 ms Action execution: Show a configurable message on the site
3.048 ms Evaluation of After updating existing content has been finished.

Why do I still get this "Action execution"?

The only way I could set it up differently is adding triggers (action: publish/unpublish) to all workflow changes. But having around 20 custom content types and 10 workflow states, I really don't like the idea of adding all these triggers manually..

Hope that someone knows a resolution to my problem!

klausi’s picture

> Why do I still get this "Action execution"?

Because yo have negated your condition, which evaluates to FALSE, so the action is executed.

Your rule fires, if [node_unchanged:workflow-current-state-name] and [node_unchanged:workflow-old-state-name] are not equal.

fago’s picture

Status: Active » Fixed

Check out this: http://drupal.org/node/370111#comment-1892040

Using this integration doesn't require fiddling around with tokens, so it's easier (and also faster).

Status: Fixed » Closed (fixed)

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