Expressions exercise

Estimated duration: 2 hours

Introduction

Novulo has its own expression language. It is used for the development of components and for the configuration of applications. It allows for the retrieval of data and the calculation of values. Novulo expressions are parsed into SQL SELECT statements during their execution. They can be built and displayed visually in the architect or as plain text.

What you are about to learn

  • What are expressions in Novulo
  • What is the expression debugger
  • How to write simple expressions
  • How to nest multiple expressions

Prerequisites

  • A personal training environment.

Contact your Novulo consultant if you do not have access to a personal training application for exercises yet. Most exercises only work in combination with a selected set of training data and not in any application.


1.The Expression Debugger Basics

Explanation for the exercise

A) What is the result of the following expression in your test application?

contacts:load(1).contact_name 

B) What is the “contact_name” of contact with id 2?
C) Is it possible to link the record type “activities” to an address?
D) What is the description of the “contact_type” of contact with id 1?
E) What is the result of the expression “this.default_currency.symbol” in the context of “contacts:load(1)”

If you get stuck, read the following posts:

Solutions

A)

My organisation

B)

contacts:load(2).contact_name → “Gebruiker, S (Standaard)”

C)

Yes, and the name of the field name is “address”. Use the button datamodel

D)

Put the expression contacts:load(1) in the context field of the debugger → €


2. Product analysis

Let’s write some more complex expressions to retrieve data about the products that are part of your training environment.
Use the following community posts if you get stuck:

Hint: Use CTRL + Space in the expression debugger for suggestions

A) Use the following expression “{products, this, true}”. How many products exist in your application? (Hint: Use the analyze button)

B) The expression products:load(1).code.equals("") results in true when the code of a product is empty. It results in false when the code is not empty. Use .code.equals("") to retrieve a list of all products with an empty product code. What are the ids of the products?

C) Write an expression to get a list of all products, sorted by id descending. What is the id of the product that appears first?

Hint: Syntax for evaluating multiple expressions

D) Get the first product, sorted by id ascending, that has a name that ends with the string “er".

Solutions

A)

{products, this, true} → 132 products

B)

{products, this, this.code.equals("")} → Product with id 230. Alternative expression that is also correct: {products, this, this.code.isnullorempty()}

C)

{products, this, true, id.desc} → Product with id 264

D)

Product with id 133 when looking at the list: {products, this, name.endswith("er"), id.asc}
Also correct: products:first({products, this, name.endswith("er"), id.asc})


3. Nested expressions

The previous examples were straight forward and only used one record type. It is possible to nest multiple expressions, much like in SQL. This can result in very nuanced data retrieval.

Use the following community posts if you get stuck:

Hint: Use CTRL + Space in the expression debugger for autocomplete suggestions

A) Use the following expression {products, <id, code, createdat.tostring()>, this.code.endswith("e")}. Expand the expression with the date time when the products were modified for the last time and the name of the products.

B) Modify the filter expression to retrieve all products. Export all data that you retrieved to a .csv file. How many products did you export?

Hint: Make sure that you increase the export limit from 100 to at least 150 before evaluating and exporting. The “Number of rows” setting is hidden under “Other” in the expression debugger.

C) Use the expression from the previous step and modify it so that it only returns products with a code that ends with “0” (zero) and starts with an “s” and a name that contains “802.11”. How many products match all criteria?

D) How many products have a name that contains “802.11” OR a code that starts with “s”?

E) With first() it is possible to retrieve only the first record of a list of records. For example, products:first({products, this, true}) returns one product. Write an expression to return the first language that has the field “is_default” set to yes. What is its iso code?

F) With the expression countries:count({ countries, this, primary_language.iso_code.equals("de")}) you can count how many countries have a primary language with the iso code “de”.
Retrieve a list of languages that have been set as the “primary language” for more than one country.

Hint: You will need to use “parent” in the part of the expression that counts the countries.

What is the ISO code of that language?

Solutions

A)

{products, <id, code, name, createdat.tostring(), modifiedat.tostring()>, this.code.endswith("e") }

B)

You should have downloaded a .csv file with 132 records after hitting the export button in the top right corner of the expression debugger.

C)

1 product with code SWLA60:
{ products, <id, code, name, createdat.tostring(), modifiedat.tostring()>, boolean:and([ this.code.endswith("0"), this.code.startswith("S"), this.name.contains("802.11") ]) }

D)

21 products: products:count( { products, this, boolean:or([this.code.startswith("S"),this.name.contains("802.11")]) })

E)

“nl” : languages:first({languages, this, is_default.equals(yesno:load(1))}).iso_code

F)

“nl” : {languages, iso_code, countries:count({ countries, this, primary_language.equals(parent)} ).isgreater(1)}

2 Likes