How do I call a server function from a Freshservice event

I have a scheduled event that is supposed to call another server function. I am getting that the function is not defined. At the moment I am thinking that the task that is executed during the scheduled event is in a different scope of the server.js file. I can think of a solution to just add the code from the function that is being called by the scheduled event task, but this is unwanted redundancy. Is there another way I can access this function?

is it possible to invoke a server function from the server?


 onScheduledEventHandler: function(payload) {
    console.log("Logging arguments from onScheduledEvent: " +  JSON.stringify(payload));
    if("name" in {
        if( === "sync") {
            console.log('starting the scheduled sync')
            try {
                somefunction(payload); //undefined error
            } catch (e) {
somefunction: function(args) {
//task to be performed

found a new app example in the docs that uses the following.

let obj = this;

This was the solution for anyone that encounters a similar issue

1 Like

Hi @osanchez,

I hope, you have found the solution. Just using this in your code snippet as follows will work. It is the normal behavior of JavaScript.