This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Actions

Actions

Process Actions

Process actions are steps which can be included in a Process.

Like all steps, they are executed unless they are nullified by some precondition being false.

1 - Update Variable Action

Update variable action

Variables

Variables are values which can be updated.

They are created within the Values tab, and can be used and updated within Process steps.

1. Updating a Number Variable

To update a Number Variable, you

  • choose the Variable you want to update
  • then you provide an expression which will give the new value

Body mass index (BMI) example

  • Underweight = <18.5
  • Normal weight = 18.5–24.9
  • Overweight = 25–29.9
  • Obesity = BMI of 30 or greater

Body Mass Index formula

In the video below,

  1. we have set up two number input questions to ask the user for weight in kg and height in m.

  2. We introduce a number variable bmi.

  3. We add an Update variable action with the BMI formula. When this executes, the value of the bmi Variable is updated.

  4. We add a text display where we include the bmi variable to inform the user of the value of bmi which has been computed on the basis of the input values.

  5. Then we debug to test it out.

Using an expression to calculate Body Mass Index (bmi)

Calculating a number of periods (months, weeks, etc.) since/until …

Another way of calculating a new value for a number Variables you might want to use is by determining a number of periods- how many months/weeks since/until from one date to another date.

Imagine you are creating an App to advice pregnant women.

As an approximation to gestation date, you may take the date of last-known menstrual period (LMP).

Then, to give good advice, your App may need first to figure out how many weeks along any particular woman is.

This is how we can compute this in Logiak:

Using an expression to calculate weeks since a certain date

2. Updating a Date Variable

We can use the example of pregnancy here too to illustrate one way we might want to calculate a new date value.

If we know a woman’s LMP (Last known menstrual period), we can also know the EDD (expected delivery date) by figuring out what the date is 40 weeks after the LMP date.

Here we create a variable edd to represent Expected Delivery Date, and calculate a value for that by explicitly saying we want the date which is 40 weeks after LMP (Last known menstrual period)

Logiak builds an expression for us.

Using an expression to calculate EDD

3. Updating a Symbol Set Variable

The following video shows creating and updating of a set Variable.

Please checkout Reasoning with Sets for explanation

Calculating a new set and updating set variable

2 - Fetch Object Instance

Fetch Instance from the database

Fetch Instance

This action fetches an object instance from the database which becomes the value of this action.

The fetch instance action needs to know which instance you want.

We describe this by

  • thinking of which instances we might want to consider (= defining filter conditions)
  • then thinking how we might sort that collection of instances so that the one we want is first.

In fact, there are three steps to configuring the fetch, and they appear in this order:

  1. You specify how to sort the objects 2.Then you say which you want to pick from the sorted list (normally the first, but you might want second, third etc)
  2. You can also add field conditions to narrow down the selection to a specific collection

Example

Suppose we needed to

Fetch the invoice with the largest amount from the past 12 months

you would configure it like this:

  1. sort by the amount field
  2. pick the first instance from the sorted list
  3. and add a field condition on invoice date so that list you are picking the instance from contains only invoices from past 12 months

Fetch Specific Instance

If you know the primary key of the instance you want to fetch from the database, you configure like this:

  1. choose to sort by any field
  2. pick the first instance from the sorted list
  3. set a field condition on the unique field, specifying that the value of that field must include

3 - Fetch Aggregate Number

Calculating an aggregate number from the database

Fetch aggregate number

This action allows you to query the database to find out things like:

  • What’s the largest invoice amount we've had so far?
  • What’s the average score students have gained on this test?

You can also add conditions and narrow the query

  • What’s the average score female students have gained on this test?

The numerical result will be stored as the value of this action

4 - Stop

Stop

Stop Action

This is a simple action which, when executed, stops the execution of the Process.

No subsequent Steps are executed.

5 - Jump

Dreaded goto

This is the dreaded GoTo

6 - Expressions and the Expression Wizard

Expressions

Expressions

To update a number variable with a new value, you can provide a new value directly, or you can define an expression from which the new value can be calculated.

The expressions you can define are the normal arithmetic expressions such as

(3 * 4)

Simple expressions, but no operations, blocks of code, control flow statements.

It supports a syntax that is common to most programming languages, including systems such as Excel.

Of course, what makes this useful is that you can calculate a new value for a variable with an expression which includes other values from the Process.

The way you do this is by building the expression as normal, but quoting other values which you want to include.

So if you have a variable called amount and you want an expression to calculae 16% tax, you could use the expression:

({amount} * 16/100)

Expression Wizard

As you are editing an update expression, you may well have forgotten exactly what name you gave to a particular value in the Process.

Instead of having to quit the editor to find out, you can make use of the Expression Wizard.

Ths formulates expressions for you, and then offers you the ability to copy and paste them in.

So you don’t need to remember:

Anything really - because this is a 100% no code system, and to remember lots of arbitrary things is not fun.

Math Functions

To build expressions use the familiar operators for multiplication,division, addition and subtraction:

You can also make use of some mathematical functions.

We will list them below, but please note they are also available for reference via the Expression Wizard

available functions

Examples

To calculate the value of amount to the power of 10, we could have the following expression:

pow({amount},10)

Expression to round the value of amount to the nearest integer

round({amount})

Constants available

Constant ´ Notes
e Base of the natural logarithms 2.718281828459045
ln2 Natural logarithm of 2 0.6931471805599453
ln10 Natural logarithm of 10 2.302585092994046
log2e Base-2 logarithm of e 1.4426950408889634
log10e Base-10 logarithm of e 0.4342944819032518
pi The PI constant 3.1415926535897932
sqrt1_2 Square root of 1/2 0.7071067811865476
sqrt2 Square root of 2

Division by zero and NaN (Not a number)

When you are calculating numbers based on other numbers, sometimes you get unfortunate situations.

One of them is when you are wanting to divide x by y, but the y has the value zero. Division by zero_ is impossible and yields infinity, which is most likely not what you intended

To avoid a crash, for cases of division by zero, we arbitarily / pragmatically assign the result to be 0.

Similarly, if there is a division by zero with a multiplication (e.g. (0/0)*100)), the result is NaN which is Not A Number.

In such a case, we also arbitarily assign the result to be 0.