Uncaught (in promise) Error: Invalid function and 400 error

I tried to execute a simple cloud function taking user address as a param. but its returning the following error.

Uncaught (in promise) Error: Invalid function

Code below

Moralis.Cloud.define(“cloudfn”, async (request) => {
const userAddress = request.params.userAddress;
const logger = Moralis.Cloud.getLogger();
const data = Moralis.Object.extend(“Testdata”);
const fromQuery = new Moralis.Query(data);
fromQuery.equalTo(“from”, userAddress);
logger.info(“working”);
const Results = await fromQuery.find();
logger.info(Results);
return Results;
});

I tried the following to resolve it didn’t work.

  1. No syntax error/warning with cloud function.
  2. The following is the way I am calling cloud function

async function cloudFunction() {
console.log(userAddress, “This is UserAddress”);
const getData = await Moralis.Cloud.run(“cloudfn”, { userAddress });
}

You can try with a simpler cloud function, like only a line with logger.info and then to add more lines in order to identify the problem.

Sure. when the results are returned, the data is not getting converted into array to save to the moralis DB. I tried to array.push but that didn’t push the object into array. Can you please help. Code below.

      let JSONStringify =  JSON.stringify(results);
      transactionsData.push(JSONStringify);
      const Transaction = Moralis.Object.extend("DataTable");
      const findQuery = new Moralis.Query(Transaction);
      findQuery.equalTo("id", tran.id);
       const transactionQuery = new Transaction();
       transactionQuery.save(results);

I don’t understand on what line is the problem