1

I have an event that is outputting data via event.renderData(data=mydata, "json").

When I access it via the browser, the JSON data is returned as expected. Though if I call the event from within another event, I only get an empty string returned. I save the output like this:

savecontent variable="local.eventResult" {
  runEvent(event="mymodule:myhandler.myaction");
}

If I dump the data within the event, it looks ok. I have tried to get the data via return event.renderData(data=mydata, "json"); and returning the data directly, i.e. return mydata;, without success.

What should I do to get the data as expected?

Community
  • 1
  • 1
Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132

1 Answers1

0

I asked a similar question on the ColdBox Slack channel and received a response that this behavior is intentional. You can not use renderData() to return output from runEvent(). Here is the response I received from Luis M:

RenderData is mostly used for the request to marshall data, not the event if you want the event to return something, then just use return

Example:

function test( event, rc, prc  ) {
  return "<p>MyViewlet</p>";
}

In your example, if you want to output data as JSON, you could use the following in your handler:

function myAction( event, rc, prc  ) {    

    var myData = {
        fruit = "apple",
        vegetable = "carrot"
    };

    return serializeJSON( myData );

}
Dave L
  • 3,095
  • 3
  • 16
  • 25