3

I successful used the data comparison on rules condition between saved and unchanged node for a date field.

I tried the same with a radio buttons list with two options, but the rule doesn't trigger if I change the value after saving the node.

What's wrong?

Here the rule: http://kopy.io/6GfFi and here is an instream copy of it:

{ "rules_last_day_of_work" : {
"LABEL" : "Last Day of Work",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "interval", "rules_conditional" ],
"ON" : { "node_update--job_contract" : { "bundle" : "job_contract" } },
"IF" : [
  { "NOT data_is" : {
      "data" : [ "node-unchanged:field-date-of-last-day-of-work" ],
      "value" : [ "node:field-date-of-last-day-of-work" ]
    }
  },
  { "OR" : [] },
  { "NOT data_is" : {
      "data" : [ "node:field-resignation-layoff" ],
      "value" : [ "node-unchanged:field-resignation-layoff" ]
    }
  }
],
"DO" : [
  { "drupal_message" : { "message" : "test" } },
  { "data_calc" : {
      "USING" : {
        "input_1" : [ "node:field-days-of-notification" ],
        "op" : "*",
        "input_2" : "-1"
      },
      "PROVIDE" : { "result" : { "days_of_notification_negative_sign" : "Days of notification with negative_sign" } }
    }
  },
  { "interval_apply" : {
      "USING" : {
        "interval" : [ "days_of_notification_negative_sign" ],
        "period" : "day",
        "date" : [ "node:field-date-of-last-day-of-work" ]
      },
      "PROVIDE" : { "date" : { "notification_date" : "Notification Date" } }
    }
  },
  { "CONDITIONAL" : [
      {
        "IF" : { "text_matches" : {
            "text" : [ "node:field-resignation-layoff" ],
            "match" : "L",
            "operation" : "starts"
          }
        },
        "DO" : [
          { "data_set" : {
              "data" : [ "node:field-layoff-date" ],
              "value" : [ "notification-date" ]
            }
          },
          { "data_set" : { "data" : [ "node:field-resignation-date" ] } }
        ]
      },
      { "ELSE" : [
          { "data_set" : {
              "data" : [ "node:field-resignation-date" ],
              "value" : [ "notification-date" ]
            }
          },
          { "data_set" : { "data" : [ "node:field-layoff-date" ] } }
        ]
      }
    ]
  },
  { "redirect" : { "url" : "[node:url]" } }
]
}   }

THE ANSWER IS: this is the way to put two condition in "OR" enter image description here

and NOT this one:

enter image description here

4
  • No, I'm on D7 :) Feb 9, 2017 at 17:41
  • Hm, looks like we're changing to Italian (field names),, no? Can you edit your question to better explain what those field names (machine names) are about? Especially are they single value, or are they multi value fields? Also, is this the rule that works (with the date field), or is this the rule which fails (for the radio buttons list with 2 options)? Feb 9, 2017 at 17:48
  • I tried to make the rule understandable. Pratically, I want the rule triggers when the [field-date-of-last-day-of-work] is changed or when the radio button with the two options: "resignation" or "layoff" is changed. (if the user makes a mistake, re-open the form and want to modify or the date of the radio button I need to modify some parameter) Feb 9, 2017 at 18:09
  • Please check my updated answer (= the 2nd attempt I added to it). Are you familiar with "entity has field", the importance of it? Ie to make fields available for further processing in subsequent Rules Conditions and/or Actions. for now it's only a guess (debugging = the art of taking away all possible causes why something does not work ...). Feb 9, 2017 at 18:27

1 Answer 1

1

1st attempt (do some debugging ...)

You clearly have a combination of Rules Conditions and/or Actions which don't seem to react as you expect/want them to do. If I was to get this to work, the first thing I'd do is Rules debugging. Rules is great, but sometimes also tough to debug if things don't work as you'd expect.

There are some typical facilities to do such debugging, but my Keep-It-Super-Simple technique I often use is my BINGO-trick (if you want, you could consider/call it "adding breakpoints to a rule you want to debug"). A sample of such rule can be found in my answer to "Which Rules condition can be used to email a user when an admin updates their profile?". Obviously, if you have more then 1 Rules Action (you seem to have (about) 4, following the "Display message test"), you may want to make it like Bingo1, Bingo2, Bingo3, etc. Depending on the order they are shown, you also know the order of execution. Stupid, but simple and efficient (I think). Here is an edited version of your rule containing those BingoX-messages (try to import it in your site, note I gave it another machine name):

{ "rules_cessazione_with_breakpoints" : {
    "LABEL" : "Cessazione with breakpoints",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "interval", "rules_conditional" ],
    "ON" : { "node_update--rapporto_di_lavoro" : { "bundle" : "rapporto_di_lavoro" } },
    "IF" : [
      { "NOT data_is" : {
          "data" : [ "node-unchanged:field-data-cessazione" ],
          "value" : [ "node:field-data-cessazione" ]
        }
      },
      { "OR" : [] },
      { "NOT data_is" : {
          "data" : [ "node:field-dimissioni-licenziamento" ],
          "value" : [ "node-unchanged:field-dimissioni-licenziamento" ]
        }
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "Bingo1" } },
      { "data_calc" : {
          "USING" : {
            "input_1" : [ "node:field-giorni-di-preavviso" ],
            "op" : "*",
            "input_2" : "-1"
          },
          "PROVIDE" : { "result" : { "giorni_neg" : "Giorni neg" } }
        }
      },
      { "drupal_message" : { "message" : "Bingo2" } },
      { "interval_apply" : {
          "USING" : {
            "interval" : [ "giorni-neg" ],
            "period" : "day",
            "date" : [ "node:field-data-cessazione" ]
          },
          "PROVIDE" : { "date" : { "data_preavviso" : "Data Preavviso" } }
        }
      },
      { "drupal_message" : { "message" : "Bingo2" } },
      { "CONDITIONAL" : [
          {
            "IF" : { "text_matches" : {
                "text" : [ "node:field-dimissioni-licenziamento" ],
                "match" : "L",
                "operation" : "starts"
              }
            },
            "DO" : [
              { "drupal_message" : { "message" : "Bingo3a" } },
              { "data_set" : {
                  "data" : [ "node:field-data-licenziamento" ],
                  "value" : [ "data-preavviso" ]
                }
              },
              { "drupal_message" : { "message" : "Bingo3b" } },
              { "data_set" : { "data" : [ "node:field-data-dimissioni" ] } },
              { "drupal_message" : { "message" : "Bingo3c" } }
            ]
          },
          { "ELSE" : [
              { "drupal_message" : { "message" : "Bingo4a" } },
              { "data_set" : {
                  "data" : [ "node:field-data-dimissioni" ],
                  "value" : [ "data-preavviso" ]
                }
              },
              { "drupal_message" : { "message" : "Bingo4b" } },
              { "data_set" : { "data" : [ "node:field-data-licenziamento" ] } },
              { "drupal_message" : { "message" : "Bingo4c" } }
            ]
          }
        ]
      },
      { "drupal_message" : { "message" : "Bingo5" } },
      { "redirect" : { "url" : "[node:url]" } },
      { "drupal_message" : { "message" : "Bingo6" } }
    ]
  }
}

I'd be interesting to hear which of those "BingoX" messages will get shown while debugging your rule ... Based on that you should come closer to finding the real reason for your rule which doesn't seem to do what you expect/want.

For more suggestions about Rules debugging, and more advanced facilities, refer to "How can I display the value of a variable inside a condition?"

Note: for those who think "this is not an answer", here is my reply to that already: do you know the story about giving somebody a fish, versus giving a fishline (or whatever that is called)?

2nd attempt (why no "entity has field"?)

About your "but the rule doesn't trigger". It may mean that you NOT (repeat: NOT) get that "test" message (as in your very first rules action). If that's the case, I'd wonder (if I was debugging) what results you get if you (temporary) remove the first rules condition? And what if you (temporary) remove the 2nd rules condition?

Hang on: you don't seem to have the typical "entity has field" condition (as your very first Rules Condtion). Imagine Rules thinks all those field values are blank (because of the missing "entity has field" ...), then neither condition is true (because of the NOT ...), so the rule works as implemented. Therefor, add such "entity has field" Rules Condition, 1 for each of the fields you are already doing those data comparisons. Then let us know the result (the bets are open ...).

6
  • Actually ypur rules log is the same of mine: 0 ms Reacting on event After updating existing content. 44.929 ms Evaluating conditions of rule Cessazione with breakpoints. edit 45.736 ms The condition data_is evaluated to TRUE edit 45.744 ms AND evaluated to FALSE. 45.757 ms Finished reacting on event After updating existing content. I follow to investigate tomorrow! Thanks a lot! Feb 9, 2017 at 23:38
  • I found the problem...For me it's not logic/intuitive the way we create OR/AND conditions, anyway Rules is a great module, so should be nice only to have more examples about this. I don't think I'm the only one newbie who crashed against this... Feb 10, 2017 at 0:02
  • @PonzioPilato so what was the actual problem you found? Feb 10, 2017 at 0:04
  • The way I combined the conditions that I put in OR, before I put them as in a normal language "a OR b" but in Rules we need to write "OR a b" :( Feb 10, 2017 at 0:07
  • it's a bit nonsense as the action "Apply an interval to a date" where you cannot subtract the interval, so I shoud multiply my interval value for -1 Feb 10, 2017 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.