Skip to Content
Technical Articles
Author's profile photo Sunoj Michael

SAP BTP Cloud foundry Job Scheduling for CAP based project

Hi All,


We might come across scenarios where we must create a CAP based application that needs to have a schedule option as well. The job had to be executed at specific intervals, like may be in every 15 seconds or so.

SAP BTP Cloud foundry have this service available in ‘Service Marketplace’ for scheduling jobs. We can just create an instance of it and bind it to our application.

This blog post explains how to create a job in Cloud foundry and schedule it for a CAP based project.

We can think of our task having two parts

A CAP Application

For my testing purpose I used the bookshop application in sap-cap-samples.

The URL for github repo:

In  CAP Project, you would need to have a task that needs to be running at specific intervals, for example, sending an Email Notification or doing some data processing etc.

We can use the concept of custom action/functions for the same. What I did is, I modified the cap-samples bookshop application service at cat-service.cds file and added a custom action handleNotification ( ) which can send out email notifications, but your use-case would be something different.


//at cat-service.cds

using { sap.capire.bookshop as my } from ‘../db/schema’;

// @impl:’cat-service.js’

service CatalogService @(path:’/browse’) {

action handleNotification ( );



The email implementation part at cat-service.js. Note that, I am using an email provider called sendgrid for sending emails.

//at cat-service.js

const sgMail = require('@sendgrid/mail')
const cds = require('@sap/cds')
const { Books } = cds.entities ('sap.capire.bookshop')

class CatalogService extends cds.ApplicationService { init(){

//Sent Email with Job
this.on ('handleNotification', async req=> {

  //to sent email    

const msg = {
  to: '<>', // Change to your recipient
  from: ', // Change to your verified sender
  subject: 'Your Subject',
  html: '<strong> YOUR EMAIL CONTENT </strong>',
  attachments: [{"content": "dGVzdA==", "type": "text/plain", "filename": "attachment.txt"}]

   .then(() => {
     console.log('Email sent')
   .catch((error) => {
//custom error message
      req.error(400, 'Error Sending Notification')

module.exports = { CatalogService }

Now that the code changes are done, kindly deploy your application in cloud foundry.


Next, Scheduling part

Now that we are having a running bookshop backend service in cloud foundry, we can proceed with the scheduling a job.

Just search for job in ‘Service Marketplace’


Create an instance of it

You can provide any name as ‘Instance Name’ I went with testjobemail.

And bind to your application

Now, for the job instance you would be having the ‘View Dashboard’ option available.

You can create a job in dashboard with necessary details as shown in figure



Next is to Create Schedule, its in schedule that we can provide the interval for executing the job.

You can see the logs for each run as well




We implemented a job and scheduled it for a CAP Service end point.

By the way, I used the trial subaccount for scheduling which have limited features like I cannot create repeating runs. But if it’s a paid version, I would be able to.

We can optimize the Service creation and binding of application by adding the details in deployer file mta.yaml.

Hope you find the blog post useful!



Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Egor Tokarev
      Egor Tokarev

      Thanks for sharing your experience. Recently we had to do the same task of scheduling a job but we've found that standard scheduling service allows only one REST service call.

      We've ended up with implementing scheduler job with cron npm package and bootstrapped it via "srv/server.js" file (anyway we had odata V2 adapter proxy) as follows:

      const cds = require("@sap/cds");
      const proxy = require("@sap/cds-odata-v2-adapter-proxy");
      cds.on("bootstrap", app => app.use(proxy()));
      //jobs bootstrap
      const { runJob } = require("./scheduler");
      cds.once("listening", () => runJob())
      module.exports = cds.server;

      Best regards,


      Author's profile photo Sunoj Michael
      Sunoj Michael
      Blog Post Author

      Thanks for the input Egor Tokarev . Ya the scheduling services have limitations to have chaining of services.

      Author's profile photo Rakesh Kumar
      Rakesh Kumar

      Hi Egor Tokarev,

      Thanks! for the valuable input.

      We tried and it seems to work for us as well, but our concern is related to security. As we want to use this for productive environment on BTP, we are not sure if the library/corn npm package, is secure enough and regular updates will be managed by anyone? Also as this is not a sap standard, we are bit reluctant to go ahead with it for production.

      What is your view/suggestion on this?



      Author's profile photo Egor Tokarev
      Egor Tokarev

      Hi Rakesh,

      That's of course up to your company's policy whether to use opensource packages or create your own.

      My personal recommendation is to use strict dependency version numbers to avoid conflicts with newer package versions.



      Author's profile photo Nandakumar S Nair
      Nandakumar S Nair

      Nice blog. Keep sharing 🙂

      Author's profile photo Sunoj Michael
      Sunoj Michael
      Blog Post Author

      Sure. Thanks Nandakumar S Nair .

      Author's profile photo Babu Pasupathy
      Babu Pasupathy

      Hi Sunoj Michael,


      We are also having the same use case, but our CAP Service have XSUAA authentication. So job scheduler getting 401 unauthorized error.


      I have  configured job scheduler instance in mta.yaml. Like below. Not sure what are we missing here.


        - name: js1
            service: jobscheduler
            service-name: js1
            service-plan: standard
            path: ./xs-job.json




      Author's profile photo Sunoj Michael
      Sunoj Michael
      Blog Post Author

      HI Babu Pasupathy ,


      To add in XSUAA support, we need to have two factors to consider.

      1. To have config set for xsuaa support set at mta.yaml- name: jobsch
        type: org.cloudfoundry.managed-service
        service: jobscheduler
        service-plan: standard
        service-name: jobscheduler
        enable-xsuaa-support: true


      2.  In CAP SRV get the job-scheduler related credentials from env.


      Hope this helps.






      Author's profile photo Krishna Bommisetty
      Krishna Bommisetty

      Hi Sunoj Michael,

      Thanks for creating this blog.

      It's great if you share some details about schedule a job using "job scheduling service instance" for the ABAP Restful programming applications?

      I would like to know how to ACTION URL get determined for ABAP Restful programming applications?





      Author's profile photo Frank Li
      Frank Li

      Great, thanks  for sharing.