Using the Rules module and Drupal 7, I set up a rule "After saving new content of type X".

This is what I want to happen when adding a new content of type "X":

Based on its nid, call a view, which returns back a JSON, from where I fetch the info to work later. The info I need is on this view, not in the node I am inserting, but to get this view I need the nid and some other info from the node I am creating

The problem is that even if I get the nid of the new node, when I call the view it just returns an empty result. It seems like the data it's still not on Drupal database, so the view results empty. I tried to add a sleep(10) before calling the view, giving some time to Drupal, but no success.

The Content is published, and I added also a 'Save entity' Action to the Rule

Hope with this code here helps to understand; it's in Editing action "Execute custom PHP code", "After saving new content of type X"

dsm($node);  //I can see al attributes from the node I am inserting



//it gives me a correct URL, that tested later directly on the browser, works
//If instead of $node->nid I use an existing nid, I get back results correctly, so the code below is correct


$data2 = json_decode($data,true);

//EMPTY array

2 Answers 2


IMO your "issue" (about "It seems like the data it's still not on Drupal database, so the view results empty") is because of the event (= "after saving new content") you are using, which might simply not be the right event.

Moreover, have a look at issue # 430274, about an event which is a variation of your event here, and somehow explains that "after saving something" actually happens ... "before saving something" (which is not a bug, simply how the Rules module works ...).

A possible compromise to avoid these kind of issues, is to transform what's you're trying to do into a Rules Component, so that your original Rule "schedules the execution" (using the Rules Scheduler submodule) of that Rules Component (eg X secs or mins "after saving that new user account" ... if your cron job runs frequent enough, if not it'll be next time cron runs). This compromise will ensure that at the time the Rules Component is executed, the content is for sure saved ... (so that can't be the reason anymore then why it would still be empty ...).


It sounds like a permissions problem with the view. Is $node->uid getting set properly?

Also, ensure the following:

  1. The anonymous user has permission to the view that you're trying to access. Check this by using Privacy/Incognito mode in your browser.
  2. Ensure the view can be seen by others.
    1. On the View editing page, under Page Settings, there will be an item that says Access.
    2. Ensure that it says None.
    3. Note that even though the item says "Access" it is short for "Access Restrictions" and having it set to none simply means that it won't be disabled.
  3. You may need to change the view to 'bypass access control' so that an anonymous user can see entries. To do this:

    1. Go to the view you're editing and expand Advanced. (1)
    2. Click on the link to access Query Settings. (2)
    3. Disable SQL-rewriting.
    4. Save your view and try again.

enter image description here

enter image description here

Your Answer

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

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