Calling custom event from business logic

Hi,

I have a custom ‘afterCreate’ event on a datable, which is calling a custom event.

afterCreate event:

class BLProjectObjectTableEventHandler extends  BasePersistenceEventHandler 
{
    
  public function afterCreate( $runner_context, $blProjectObject, $execution_result ) {
  		
  	echo "\n";
  	echo "Create 'Create' action for ";
    echo "ProjectObject - ". $blProjectObject->getName() ." Created";
    echo "\n";
        
  	$event_args[] = ["blProjectObject" => $blProjectObject];
  	$event_args[] = ["action" => "Create"];
  	
  	Backendless::$Events->dispatch("addQueueEntry", $event_args);
}
}


Custom Event:

class AddQueueEntryEventHandler extends  BaseCustomEventHandler
{
    


  /** @annot( { "handleEvent":{"Async":"true"}} ) */


  public function handleEvent( $runner_context, $event_args ) {


    // add your code here
    print ("test");
}
}

When the afterCreate method is called Im getting this error:

Create ‘Create’ action for ProjectObject - regeert Created
[ERROR] In Backendless SDK occurred error with message: “Backendless API return error: Only JSON object is allowed in request body. Error code:20013”

Any idea how to solve this?

Thanks!

Hi Guys,

Just a little kick as I really need this to work :slight_smile:

Also: are there plans to support php for hosted API service?

Thanks a lot,

Barry

Barry,

Calling custom business logic from within business logic via API is not allowed. This is done to prevent recursive behavior which may lead to system instability.

Instead of invoking custom event via Backendless::$Events->dispatch, you can call the method of the custom event handler directly and it should work.

Regards
Mark