example6: time channel, mail channel and new action types

posted in: Uncategorized | 0

Now that you’ve experienced the application data channel and the auditing channel it´s time to introduce you to the time channel and the mail channel. The time channel allows you to fire rules at specific times or moments. You can make a rule that will be executed daily, weekly or monthly. To show you how everything works we will show you how to make a rule that every day looks for all listings that are featured and have 5 or more bathrooms, if there is at least 1 result then send a mail with the result.

-every day at 8:00 AM

-look for all listings that pass this filter: listings that are featured or have more than 5 bathrooms

-if there is 1 or more result, send a mail with the result

So to start with the first one. Open the Timed triggers channel to start.

Image 088

You will see that there are 3 kinds of events. Daily event, weekly event or monthly event. In the daily event you only have to specify the hour and minutes you want to start the event on. In the weekly event you have to also select which day of the week, and In the monthly event you have to select the hour, minutes and which day of the month you want the rule to be executed.

For this example we want to execute this rule every day. so use the daily event.

Image 089

Change the hour to 8 AM and click on the accept properties button on the bottom right to continue.

Image 090

Click then to add the action

Image 091

Now look for all listings that match a certain pattern. So open the application data channel and you’ll see that there are a couple of new actions there called ‘look for xxxx’, which is exactly what you’ll need for his example! Every day at 8AM we want to look for all listings that pass the filter. So click on the ‘look for an existing listing’

Image 092

Image 093

So now we want to filter out only the listings that are featured and have 5 or more bathrooms. So the filter will have to check if:

listing.isFeatured==true

OR listing.NumberOfBathrooms >=5

let’s start with checking if it’s featured. Just like last time we advice you to put each criteria between brackets to make it more readable. So add a ‘(‘ and open the variables screen. Open the look for an existing listing action, then open listing entity and scroll down to the isFeatured variable. Add ‘==true)’ after this to check if it is featured.

Image 094

Now that the first criteria is ready, glue the other one to it. But this time only one criteria has to be matched in stead of all of them. So use the OR operator by adding || to the formula. Open a new bracket and add the listing.NumberOfBathrooms variables. Finish by adding ‘>=5)’. Click on accept properties when ready.

Image 095

As you can see there are now some different action types because we have been using the ‘look for xxxxx’ action. We’ll shortly explain them to you:

-No results:

This will fire the next part of the rule only when there are no result. with this you could configure the rule that if there are no listings featured or have more than 5 bathrooms then send a mail saying ‘there are no featured listings today’.

-One or more results:

When using this action type, the next part of the rule will only be executed when there is at least one result. In the ‘no results option’ and in this option you will not be able to access the variables of the listings because you are talking about the collection of listings and not individual listings. You could for example configure the rule to send a mail when there is at least 1 result saying ‘there are featured listings today’.

-For each

Unlike the previous two options the for each options loops over the collection of results. So the next part of the rule will be executed for every result individualy, and we are no longer talking about the total collection. Because we are using the individual results again we can use the variables from the listings again. You can for example configure the rule to send a mail for each result saying the name (listing.Name variable) of the listing.

-Combine

This will combine all the individual results into a single chain and store it into a new variable. You have to select which part of each result you want to use and what you want string you want to use to glue them together. Example: use the combine option to make a new variable that contains all the Names of the featured listings with a comma between them. Then you can use this result in a mail to show all the featured listings of that day.

Image 096

For this example we will keep it simple and just check if there are featured listings to send a mail saying that there are some today. So select the one or more option.

Image 097

Now we will use the email channel to send a mail. Select the Email channel.

Image 098

As you can see there are some options. We have preconfigured gmail, outlook and yahoo! but if you want to use your own self-configured server then select the last option (send an email), in this case you will have to provide some extra information like the port and name of the server. To keep it simple, use the preconfigured gmail action. If you don’t have a gmail account then feel free to play arround with the other actions, they are pretty similar.

Image 099

Fill out all the required fields such as name, email, password and receiver information. you can also use it to send mail to yourself. If you click in the body field you will see that the editor will be activated and you can change the layout of your mail or add images.

Image 101

Click accept properties when ready. Now it’s time to finish your rule by selecting the finish rule option and completing everything with an appropriate name and description.

Image 102

Image 103

– application link
– 
Intro: sample application tour
– rule 1: Authorizing who can continue to create a new record 
– rule 2: Understanding variables
– rule 3: Set a default value on new records
– rule 4: introducing channels
 rule 5: recap: audit
– rule 6: time channel, mail channel and new action types
– rule 7: audit when rule fired
– rule 8: Make a newsletter.