ERROR : $schedule & $db is not defined in serverless app

Hi Community,

I am having issues working with schedules & accessing Data Storage API from the serverless app.

When i tried using schedule and db in server.js, it throws an error ReferenceError: $db is not defined & ReferenceError: $schedule is not defined

I have attached the screenshots of the error. Please help me resolve this issue.

Schedule Code Snippet :

$schedule
	.create({
		name: `service_task_${data.ticketId}`,
		data: { taskData: data },
		schedule_at: time
	})
	.then(
		(data) => console.log(data),
		(err) => console.log(err)
	)

DB Code Snippet :

$db.set("ticket:101", { taskId: 15213 }).then(
	function (data) {
		console.log(data)
	},
	function (error) {
		console.log(error)
	}
)

DB Error :

Schedule Error :

FDK Version :

fdk-version

Thanks,
Arshath

Hi Arshath,
May I know under which event handler is this snippet written?

1 Like

Hi @ManiDeepak_Vandrangi,

Thanks for your reply.

I have used it in onScheduleEvent & my custom method in server.js.

 exports = {
       events: [{ event: "onScheduledEvent", callback: "onScheduledEventHandler" }],

      onScheduledEventHandler: function (payload) {
	     handler.scheduleHandler(payload)
      },
      serviceTask: function (payload) {
	     handler.serviceTaskHandler(payload)
	     renderData()
      }
}

Hi Arshath,

Are you trying to invoke this event from custom installation page? If so, in custom installation, we do not support data storage($db) and schedule($schedule).

1 Like

Hi @ManiDeepak_Vandrangi,

I have used the $schedule & $db in server.js file.

BTW, i am not receiving the error anymore in my machine. I don’t know what was the reason for the error. And, don’t know how it resolved automatically :upside_down_face:.

Thanks for your reply.