In memory FoundSet

Questions and answers for designing and implementing forms in Servoy

In memory FoundSet

Postby jeffrey.vandenhondel » Thu Aug 11, 2016 11:54 am

Hi again :),

I get the following error message.

Code: Select all
Exception executing calculation: show_filter_result of table temp_9_66a7fe01_5cad_4707_9cf0_220c2a519bf2, error: org.mozilla.javascript.EcmaError: ReferenceError: "elements" is not defined.
ReferenceError: "elements" is not defined.
   at show_filter_result (show_filter_result_)


This is my code:
Code: Select all
   var countLabel = form.newLabel('countLabel', 420, 10, 240, 28);
   countLabel.name = 'count'
   countLabel.styleClass = 'result_title';
   countLabel.dataProviderID = 'show_filter_result';
   var count = "function show_filter_result() {\
      var filterSize = foundset.getSize();\
      if (filterSize == 1) {\
         elements.lblResult.text = i18n.getI18NMessage('afl.lbl.oneInvoiceFound');\
      } else {\
         elements.lblResult.text = i18n.getI18NMessage('afl.lbl.thereAre') + ' ' + filterSize + ' ' + i18n.getI18NMessage('afl.lbl.invoicesFound');\
         }\
      };";
      
   var   dataSource = solutionModel.getDataSourceNode(form.dataSource);
      dataSource.newCalculation(count, JSVariable.TEXT);
      form.getLabel('countLabel');


I tried to create a in memory calculation.
jeffrey.vandenhondel
 
Posts: 25
Joined: Thu Jul 28, 2016 9:05 am

Re: In memory FoundSet

Postby Bernd.N » Thu Aug 11, 2016 4:25 pm

Hi Jeffrey,
I would try to make the code more simple. So in case it is not necessary to stuff the function into a var string, I would turn that into a normal JS function first.

BTW, foundset.getSize() will show you max. 200 records, even when 1.000 invoices exist.
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 480
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany

Re: In memory FoundSet

Postby patrick » Thu Aug 11, 2016 6:34 pm

Without trying to understand what you are trying to accomplish I do see two things that go completely wrong:

1. A calculation resides on the data level and can never deal with forms or elements of such

While a form can use calculations when it is based on a table, a calculation is lower in the stack than a form and therefore does not have access to forms.

2. A calculation calculates a value and therefore always needs to return something

Your code is a method, not a calculation. It tries to manipulate, not calculate something.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3622
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: In memory FoundSet

Postby Bernd.N » Thu Aug 11, 2016 9:07 pm

I would recommend to use the solution model only when it is really necessary.
If it is, I would first study existing code to get some ideas of strategies to use it.
Your learning curve will be much steeper.

The Data Record Editor is an example for the use of the solution model, it shows any record in a window in editable mode.
So it just builds a large detail form with all necessary fields when you give it a table structure.
https://www.servoyforge.net/attachments/download/1571/Screenshot_Example.PNG

You can get the sourcecode here:
https://www.servoyforge.net/projects/editwindow
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 480
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany

Re: In memory FoundSet

Postby Bernd.N » Sat Aug 13, 2016 2:49 am

Ok, now I finally got what you wanted to do and mixed up, after reading Patrick's comment twice.
You could try the concept of a calculation (= automatically calculated (virtual or physical) field of a table) first on a table with manual coding, to get what it's doing.
Click the tab "Calculations" in the table editor inside Servoy developer and add a new calculation there.
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 480
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany


Return to Forms

Who is online

Users browsing this forum: No registered users and 4 guests

cron