# Calculation questions

**URL:** <https://forum.servoy.com/t/calculation-questions/3385>\
**Category:** Classic Servoy\
**Created:** [January 6, 2005, 8:17am UTC](https://forum.servoy.com/t/calculation-questions/3385 "2005-01-06T08:17:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [January 6, 2005, 8:17am UTC](https://forum.servoy.com/t/calculation-questions/3385/1 "2005-01-06T08:17:34Z")

</div>

Hi,

Got a couple of question on using Calculations:

- Can I savely use databaseManager.hasRecords(relation) inside an (unstored) calculation?

- Per table in my solution, I have to store an ID, used in relations. As far as I can see: two options: create a global variable per table, or create an (unstored) calculation on every tabel, with a simple “return x;” (x being an integer). What are the pro’s and con’s of both solutions, performance wise? (From a coding perspective, I like the calculations more.)

Hope someone can shed some light…

Paul

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [January 6, 2005, 8:01pm UTC](https://forum.servoy.com/t/calculation-questions/3385/2 "2005-01-06T20:01:46Z")

</div>

1. NO. If you can’t see it in the “tree” in the calculation dialog, then you cannot use it in a calculation.

2. I would use a global. Globals are in-memory variables - whereas unstored calcs have to be evaluated and returned.

Why are you using one per table? Is it something like the “currentID” or something like that?

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [January 7, 2005, 8:03am UTC](https://forum.servoy.com/t/calculation-questions/3385/3 "2005-01-07T08:03:54Z")

</div>

hi Bob,

Regarding 1: It does work though… question was if it’s save to use…

Regarding 2: In my solution there are certain tables containing records that are linked to multiple other tables. for example the translation table. it holds translations for records of multiple tables. Based on the Id stored agains a table and the tableId column in my translations table, I can find the right record.

Here’s the content of my Calculation (on the products table)

```auto
if(databaseManager.hasRecords(products_to_translations))
{
	return products_to_translations.translationtext;
}
else
{
	return productname;
}

```

And the realtion from products to translations is defined as follows:  
products.productsID = translations.entityid  
products.tableid (= Calculation) )= translations.tableid  
globals.application\_language (global with current language) = translations.languagekey

Paul

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [January 7, 2005, 5:52pm UTC](https://forum.servoy.com/t/calculation-questions/3385/4 "2005-01-07T17:52:11Z")

</div>

Hi Paul,

Regarding #1 - if it’s not in the tree - it’s NOT SAFE. DO NOT DO IT. ![:D]( "Very Happy") Hopefully that’s pretty clear. Your performance will suffer terribly!

Regarding #2 - I sort of get it. Can’t you use i18n for that stuff?

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [January 10, 2005, 7:53am UTC](https://forum.servoy.com/t/calculation-questions/3385/5 "2005-01-10T07:53:50Z")

</div>

Hi Bob,

regarding #1: I think I get it ![:D]( "Very Happy")

regarding #2: I’ve been looking at that, but since I18N has a key that consists of only one column/field, it’s not very neat.

I’d have to concatenate the key on the search side on the fly, by concatenating products.productsID, products.tableid and globals.application\_language into one string and store the translations against such a key.

Question is: Will that be faster? Won’t the search for the I18N text, that comes from the DB as well, be triggered just as much as the wrong solution I currently use?

Anyone else have neat design tricks for this issue? ![:D]( "Very Happy")

Paul

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [January 10, 2005, 4:45pm UTC](https://forum.servoy.com/t/calculation-questions/3385/6 "2005-01-10T16:45:25Z")

</div>

hi Bob,

Seems I solved my own problem ![:wink:]( "Wink")

Got two options:

- Using the hasRecords(relation) function of Utils (is enabled under calculation editor, so it should work

- or:

```auto
var text = products_to_translations.translationtext;
if (text != null)
{
	return text;
}
else
{
	return productname;
}

```

Both should be “legal”, so my issue is solved ![:)]( "Smile")

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [January 10, 2005, 5:31pm UTC](https://forum.servoy.com/t/calculation-questions/3385/7 "2005-01-10T17:31:21Z")

</div>

Yep - GREAT SOLUTION!
