1

This is a follow-up question of: How to delay the execution of a rule for 5 minutes?

When not delaying the action, the node:url token does not return the alias URL, but the URL with the token ID: ...node/id. I assumed this is because this URL is simply not available yet. I have to use the clean URL, because otherwise a scraper would get a HTTP status code 302 and is unable to scrape the page correctly.

I'm using the Pathauto module to create the URL's automatically.

However, when using the sheduler, I'm still not getting the clean URL. These are my current settings:

screenshot

The marked token in the screenshot should return the clean URL, but it returns the unclean /node/id one. I've already tried to change the token to [entity-fetched:url:path], but this seems to return an invalid URL (or no URL at all, is it possible to debug this?).

Why can't I get the clean URL using tokens in rules?

The weird thing is... if I edit a node instead of creating a new one, node:url does return the clean URL, but not when using the sheduler.

EDIT:

{ "rules_publish_to_fb" : {
    "LABEL" : "Publish to fb",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_scheduler", "fb_autopost_entity" ],
    "ON" : { "node_insert" : [], "node_update" : [] },
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : {
              "event" : "event",
              "inspiration_theme" : "inspiration_theme",
              "news_item" : "news_item"
            }
          }
        }
      },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_facebook_message" } },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_facebook_published" } },
      { "NOT data_is_empty" : { "data" : [ "node:field-facebook-message" ] } },
      { "data_is" : { "data" : [ "node:status" ], "value" : "1" } }
    ],
    "DO" : [
      { "schedule" : {
          "component" : "rules_facebook",
          "date" : "+2 minutes",
          "param_node" : [ "node" ]
        }
      }
}

And

{ "rules_facebook" : {
    "LABEL" : "facebook",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "fb_autopost_entity" ],
    "USES VARIABLES" : { "node" : { "label" : "node", "type" : "node" } },
    "ACTION SET" : [
      { "entity_fetch" : {
          "USING" : { "type" : "node", "id" : [ "node:nid" ] },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "entity_create" : {
          "USING" : {
            "type" : "facebook_publication",
            "param_type" : "link",
            "param_user" : [ "site:current-user" ]
          },
          "PROVIDE" : { "entity_created" : { "facebook_link" : "Facebook link" } }
        }
      },
      { "data_set" : {
          "data" : [ "facebook-link:field-facebook-message" ],
          "value" : "[node:field-facebook-message]"
        }
      },
      { "data_set" : {
          "data" : [ "facebook-link:field-facebook-link" ],
          "value" : "[entity_fetched:url]"
        }
      },
      { "publish_to_facebook" : {
          "USING" : { "publication" : [ "facebook-link" ], "pages" : "1247812435236072" },
          "PROVIDE" : { "facebook_publication_id" : { "facebook_publication_id" : "Facebook publication returned ID" } }
        }
      },
      { "drupal_message" : { "message" : "[entity_fetched:url]" } }
    ]
  }
}
1
  • Have you tried without using fetch entity by id and using node:url ? or with site:current-page:url
    – No Sssweat
    Mar 3, 2016 at 11:05

1 Answer 1

1

Option 1 (a): Try another token

Check what result you get by using either of these tokens:

  • [site:current-page:url].
  • [node:node-path].
  • [node:node-url].

Option 1 (b): Pass the URL as an extra parameter

Inspired by the answer to the question "Send node path alias to user", you might be more lucky to get access to the correct value of your URL (or either of the tokens I suggested above) if you just pass that value to your Rules Component as an extra parameter (so on top of the "node" parm you already have). And of course use the value of that parameter in your Rules Component instead.

The reason why I think you may be more lucky, is that you already have that "node_is_of_type"-condition. So because of that, and similar to the answer in the above mentioned question, it should be available in your first rule in which you schedule the Rules Component.

Option 2: Perform Rules debugging

If Option 1 doesn't help, then I'd recommend you to do some further debugging of your actual rule, as detailed below (and in the order specified).

Basic 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. 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?". Stupid, but simple and efficient (I think).

Debugging using Rules settings

Something else that might help to find the answer to your question, is to have a look at Rules debugging ... Within the Rules settings, experiment a bit with the debugging facilities that come with the rules module. At least have a look at the "Rules Evaluation Log" (to check that the Rules logic being executed, actually matches what you expect that logic to be).

Debugging using the Devel module

Depending on what the result of that type of debugging is, you may also want to (temporary) enable the Devel module, so that you can (temporary) add a Rules Action like "Display a value".

Video tutorial about Rules debugging

Refer to the (great!) video "Debugging rules configuration" for way more details about the last 2 variations.

11
  • 1
    Thanks, working on it now. When using option 1, I get example.com/nl/admin/reports/status/run-cron as the URL.
    – Bv202
    Mar 3, 2016 at 12:02
  • 1
    With debugging, [node:url] returns the bad url, no matter what... and when editing the node instead of creating a new one, I get the correct url...
    – Bv202
    Mar 3, 2016 at 12:09
  • 1
    Yes, of course I know why I'm getting the url with "reports" in it. What I mean is that node:url always gets me the wrong url (with node/id) instead of the alias one.
    – Bv202
    Mar 3, 2016 at 12:20
  • 1
    OK, these exports help a bit to better understand your rules. To further debug them, make a temporary copy of it in which you only keep the 1st (entity fetch) and last (display message) action. And in between I'd add an action like "display a value" (using the Devel module you will get such Rules Action), to get an idea of the content of that "entity_fetched" (what's available, and do the values match what you expect). PS: I suggest you delete your comments which do not have a "1" in front of them, to get rid of that (annoying I think) "chat"-thing, which "I" really do not like ... Mar 3, 2016 at 12:45
  • 1
    Complete different thought: since your "funny" URL (with "reports") includes "nl", I wonder if the reason for your issue could be because the node you try to use is available (translated) in multiple languages (i18n ???). Do you have a node which is the same for all languages to experiment with also (to see what result you get in that case). And I've not checked (yet) if "entity_fetch" maybe expects you to specify a language code or anything like that. If that's the case, and since I don't see it in your rule, it could be that you get the node in the "default language". Does that have a path? Mar 3, 2016 at 13:02

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.