1
votes

Using Rules modules, I set up a rule "After saving new content of type X". So, adding a new content of "X" should:

  1. 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:

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

$data=file_get_contents($url);

$data2 = json_decode($data,true);

dsm($data2);
//EMPTY array
1

1 Answers

0
votes

I guess you are passing nid as string not as variable in URL. $node->nid is not getting substituted. So use following code snippet

$url="http://localhost/bopa/?q=export_cultivos/".$node->nid;