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?

2 Likes

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).

2 Likes

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.

1 Like

Hey Folks,

We are facing the same error again :frowning_face:

Is the error same as above mentioned screenshots for the above mentioned snippets? If so, are you using the latest version of fdk?

2 Likes

@ManiDeepak_Vandrangi Yes same error, we receive this often. Then suddenly it resolves automatically. Could you please help find us the issue?

@arshath.h does this happen in FDK events testing or when you try to use the end to end testing feature?

2 Likes

@prithvi This happens in FDK events testing.

Hi Community,

In local, recurring schedule It’s working properly. Error occurs only time based schedule.

Solution:
Publish and install your custom app in portal. It should works proper.

thanks.