How to invoke a custom service from other backend code (event handler) in JavaScript?

I just can’t figure this out. I have CodeRunner locally and my project folder has an event handler afterCreate inside /handlers/persistence/tablename/create. That is successfully being triggered by calls to create new records.

I have a simple hello world service created inside /services/SearchService.js

'use strict';

class SearchService {
  

  /**
   * @param {String} name
   * @returns {String}
   */

  helloWorld(name) {
    return "hello " + name
  }
}

SearchService.version = '1.0.0';

Backendless.ServerCode.addService(SearchService);

But what do I put into the event handler code to call it? Below are some things I tried. I suppose I could write REST calls but the docs seem to imply there’s a way that’s built in but I need it spelled out for me apparently.

Backendless.ServerCode.Persistence.afterCreate('slots', async function(req, res) {

 const s = new SearchService();     //doesn't work, error
 Backendless.SearchService.helloWorld('abcd') //doesn't work, error 
 Backendless.CustomService.invoke( 'SearchService', '1.0.0', "helloWorld", ['abcd']); //doesn't work, error 
 Backendless.APIServices.invoke('SearchService', 'helloWorld', ['abcd']).then(function(result){
       //doesn't error but doesn't get called
})
    
}, true);

appreciate any help!

found the answer after another round of googling. I’m just less familiar with when to use the await keyword. including for posterity these both work:


await Backendless.APIServices.invoke('SearchService', 'helloWorld', 'abcd').then(function(result){
   console.log(result);
})
const result = await Backendless.APIServices.invoke('SearchService', 'helloWorld', 'abcd');
console.log(result);