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 $url="http://localhost/bopa/?q=export_cultivos/$node->nid"; dpm($url); //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 sleep(10); $data=file_get_contents($url); $data2 = json_decode($data,true); dsm($data2); //EMPTY array