Server side Script example


#1

Hello
This is my problem:
I have a Dreamfactory 1.9.4-0 database with a field “DateOfExpiration” in a server. A lot of user can add elements in the database; every user have his email in another field of every element in the database.
Every day I want to check if an element in the database is near to expire (with a server side script, I think); if the script find an element near to expire, it must send an email to the user to advise him about the coming expiration.
Can you tell me where I can find some examples to understand how to do that please ?
Thank you
Goodbye


#2

You want to check every day:-
For that you may want to use cron job, which calls your custom script everyday.

For the rest of the things, you can explore custom script, which is exposed in the form of webservice to the outside world. In that you can access your DB and do the logic check etc, and also can send email from the email service configured.

Hope that helps!


#3

There is somewhere a similar example to my needing, to learn how to do that ?
I have a service (database) and in it a table (dbtest2).
In dbtest2 I have the field DateOfExpiration for every record.
Maybe I must use something similar to:

function send_email(account_name, account_value) {

var data = {
    "to": "billappleton@dreamfactory.com",
    "subject": "Big Account Created!",
    "body_html": "Account: " + account_name + " has a value of: " + account_value,
};
platform.api.post("email", data);

}

if (event.request.body.NumberOfEmployees > 5000) {
send_email(event.request.body.Name, event.request.body.AnnualRevenue);
}

that I saw in your pages, but I’m not able to adapt this example to my real needing.
Farther how I can join the cron job to make him able to fire the script ?
Thank you again for the help
Goodbye


#4

Another thing to say: the Bitnami Dreamfactory 1.9.4-0 run under Windows 8.1.
Goodbye again


#5

A cron job can make an API call to your script using cURL. Here’s an example from StackOverflow.