Juan Pieterse
Posts: 0
Joined: Sat Apr 25, 2015 1:47 pm

Conditional events

How do I trigger an event on a certain condition, for example, I've got an event triggered on page load. This event writes to a database. How can I conditionally trigger this event, i.e. only write to a database where IF localstorage-Variable-X = "True"... i.e. I'd not like services to be invoked all the time, but confitionally.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Conditional events

Hello Juan,

Do you mean call events programmatically?

Juan Pieterse
Posts: 0
Joined: Sat Apr 25, 2015 1:47 pm

Conditional events

Hi Alena. That would be very useful too!
If you refer to the added image, you'll see that I've got 3 actions that run on the load event of my page. I would like the 3rd one (marked in red) to run ONLY on a certain condition, (for example, if local storage variable X = "True")
What is the best way to approach this? Do I take out the 3rd action and (somehow?) run it with code? Where can I put in conditional ("if") statements?
Thanks!!! Image

Juan Pieterse
Posts: 0
Joined: Sat Apr 25, 2015 1:47 pm

Conditional events

Hi there.. Please see my post below. Thanks in advance! :)

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Conditional events

Hi Juan -

You can select in this event menu Action - Run JavaScript and write the needed condition for your service execution:

precode
// here is your condition
if (X == 'true'){
// here should be the name of your service
serviceIntanceName.execute({});
}
/code/pre

Juan Pieterse
Posts: 0
Joined: Sat Apr 25, 2015 1:47 pm

Conditional events

Brilliant!! - Are the service instance names the names of the services aslisted in under "Services" in the left-hand panel?

Juan Pieterse
Posts: 0
Joined: Sat Apr 25, 2015 1:47 pm

Conditional events

Mr Stephanov!! Thank you so much for this! It works wonderfully! You're the man!!

Return to “Issues”