Calling a Server Function from Another Server Function

My GenerateReport client function calls the needed server function StageReportServer asynchronously and if successful, in the client callback calls five.selectAction( reportID, { UserKey: userKey, RunKey: runKey } );

This is working fine for the on-demand reports. But for my automated emails with attached reports functionality, I’m having an issue. The client GenerateEmails function calls the GenerateEmailsServer function. That server function also needs to call StageReportServer. This time, I’m calling synchronously like this:
const stageResult = StageReportServer(five, parms, {});

But this time, I get
Error during "generating reports": StageReportServer is not defined

ChatGPT says something about different scope, and the server function can’t see the other server function unless it’s contained in the same JavaScript function.

Can you please advise the proper way to do this, so a server function is visible from both client and another server function? I believe Libraries won’t work, because I think they are callable from client functions, not server functions. but please correct me if I’m wrong.

I notice that the Libraries tab is visible in the function screen, even in a server function, but am unsure how to use this from a server function.

Thanks…

Hi Ron,

In the return of a callback function, you can call another callback function, and even use the value from the first returned to feed the second call.

However, from one server side, you cannot directly call another server side, unless you use a library as an extension or define the function under the same code. (like in the GenerateEmailsServer, which has various functions defined).

I am not sure the rules/conditions you need to generate the report, but you can trigger it via jobs if you want it to be executed in a specific period, or attach it to the table event, so a function will run after a table has changed/updated/deleted.

Regards,
Elton S