Page 1 of 1

Conditional events

Posted: Sat Apr 25, 2015 1:47 pm
by Juan Pieterse

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.


Conditional events

Posted: Sun Apr 26, 2015 6:38 am
by Alena Prykhodko

Hello Juan,

Do you mean call events programmatically?


Conditional events

Posted: Sun Apr 26, 2015 6:56 pm
by Juan Pieterse

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


Conditional events

Posted: Sun Apr 26, 2015 7:01 pm
by Juan Pieterse

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


Conditional events

Posted: Sun Apr 26, 2015 7:36 pm
by Illya Stepanov

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


Conditional events

Posted: Sun Apr 26, 2015 11:14 pm
by Juan Pieterse

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


Conditional events

Posted: Mon Apr 27, 2015 9:54 am
by Juan Pieterse

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