Skip to main content
12-Amethyst
September 12, 2023
Solved

Scheduler Thing Template has Subscription, in that Subscription I need to call a Thing Service

  • September 12, 2023
  • 1 reply
  • 3020 views

I have a Thing Template of type Scheduler, where I have a Subscription. I have written a some scripts inside that Subscription, which is working fine. But when I try to call a Thing Service that Subscription is not getting executed.

Kindly share a sample code snippet. Thank you

 

 

Best answer by Velkumar

Hi @SKannapiran 

 

You can call ThingService inside Subscription it will work.

 

But based on your code, you are retrieving data from the session which is not going to work if it is executed by Scheduler or Timer Event. 

 

For example : 

 

1. I have session value 'testSession' and I can retrieve it from browser session

Velkumar_0-1694592205912.png

 

2. When I try to log that value using the timer event it will be always null because timer/scheduler event will be executed on the server side which doesn't have any session value.

 

Velkumar_1-1694592277004.png

 

Velkumar_2-1694592411639.png

 

So your service will run when you execute manually. But if you are going to run through scheduler / timer event it is not going to work. 

 

/VR

 

1 reply

19-Tanzanite
September 12, 2023

Hi @SKannapiran 

 

If you have a subscription in Scheduler, the subscription will be triggered based on CRON string configuration. 

 

But when I try to call a Thing Service that Subscription is not getting executed. - Could you please explain this part a bit more. Why do you want to trigger a Scheduler Subscription using the service and its use case.

 

/VR

 

 

12-Amethyst
September 12, 2023

Hi VR,

 

Use Case - To create a dynamic scheduler to send an email with file attachment based on the CRON.

 

Step 1. To create a dynamic Scheduler using a ThingTemplate of type Scheduler ===> creating successfully

Step 2. This dynamically created Scheduler is triggering based on CRON ===> triggering successfully

Step 3. In that Scheduler we have a Subscription which needs to generate a file and post it on the System Repository folder

Step 4. Upon the file availability, send that file as an email attachment

 

Step 3 & 4 are written as Subscription in Scheduler. First part of the code is responsible for generating file and second part will send an email.

Code to send email is working fine (second part), but file creation code (first part) is not working. Hence we want to trigger this part through a Thing Service call inside the Subscription.

 

Hope this clarifies your doubts. 

 

19-Tanzanite
September 13, 2023

Hi @SKannapiran 

 

Is the service (created in step 3) running without any error when manually executed?

 

Could you please share the code here and some images?

 

/VR